The ViewModel object Is being called twice.

Topics: Issues / bugs
Aug 15, 2012 at 4:50 PM

Right now I am just looking for hints....

 

I am trying to show a list of clients.  So:

1.  I have one User Control View and a MainViewModel  that holds the list of Clients. 

2.   I have  ClientViewModel that holds one row of client data. 

3.   The MainViewModel loads the data and populates a ObservableCollection of ClientViewModel objects.

4.   I am using MEF but I am not using it to compose my objects since they are all in the same assembly and name space of a plugin. 

When I create the User Control View Object I hand it to AvalonDock,.  When I click on the tab,

1.   The MainViewModelObject is created and the constructor is called.

2.  The ObservableCollection for the Client Details are requested, but at this point it is null.

3.  The Initialize for the MainViewModelObject is called.  I would normally load the data here, but am not for testing.

4. The IViewMode ViewModel Property is Accessed in UserControlView.

5. Then the MainViewModelObject is created a second time.

6. The Constructor is Called, But Not Initialize.

7.  The ViewModelChanged.SafeInvoke is now called.

8.  The IViewMode ViewModel property is accessed again.

9.  The MainViewModelObject Initialize is now called again.

10. The UserControl is now displayed with an empty grid.

 

I did this with the Data Access turned on, but to no effect.  I had some MEF imports running on these objects but turned them off as much as I could find.

I also commented out the MEF registration, just to see if it would have an effect:

     //ServiceLocator.Instance.RegisterExternalContainer(MEFContainer);

Like I said right now I am just trying to find out if you "Smell" anything obvious.  If I have to I will post as reduced code as I can.

Thanks.

Coordinator
Aug 20, 2012 at 6:48 AM

Do you have a small repro so I can test this?