This project has moved. For the latest updates, please go here.

View initialized too soon

May 3, 2011 at 6:33 PM

I am probably missing something small but...I am stuck. I am attempting to do basically the same thing you have in your RegionManagement quickstart - when the application loads I was to show the debug logger and a login. My problem is that in my MainPage.xaml.cs when the OnImportsSatisified is fired, there is nothing listening for ViewNavigationArgs events - so when I tell it to navigate to those views nothing happens. This behavior changes once the app is fully loaded up, I can then use buttons to do it and it works fine.

So, stepping through my project vs your quickstart I can see that your MainPage.xaml.cs constructor is getting fired at a completely different time then mine.

My constructor gets triggered in ApplicationServices.cs, StartService, where it says CompositionInitializer.SatisfyImports(this). So my constructor fires and right after the OnSatisfyImports fires, at which point there is nothing listen.

Your constructor gets triggered in ApplicationServices.cs, Starting, where it says Application.Current.RootVisual = viewInfo.Value.

I have tried to find the differences in our projects and what I am missing but I am at a loss. Can you help me figure this out?

Coordinator
May 3, 2011 at 6:36 PM

Why not move your logic to the view model - does it have to be in the view? The view model is the logical choice, and if you put it in _initializevm should be the right timing too.

May 3, 2011 at 6:50 PM

Yes, it does belong in the VM. my concer was that if my stuff is not set up correctly then spending time trying to work around it would be wasted. Techinically this is the shell view. i will try moving the code but what would cause my shell to load differently then the quickstart?

Coordinator
May 3, 2011 at 6:59 PM

Could be a number of things but the correct setup is in the view model and that's the whole purpose of having those methods is to hook into the process at the right touch points. Shouldn't be a work around to use the view model.