2
votes

I programming a WPF GUI that uses multiple Views. I am using the MVVM Light Toolkit to implement the MVVM pattern.

For Navigating i use this mechanism by changing my main frame to a NavigationWindow and all my views to Pages.

I injected the navigation service in the ViewModel constructor and now I can navigate between the views.

However, i would like to transmit data between the views while navigating. There is a method from Navigation Window that makes this possible through event handlers. I already implemented a method into my Interface but I'm having problems calling the event handler on the navigated View Model.

Can anyone tell me how to call the event handler inside my ViewModel?

Thanks!!

Edit: I tried calling:

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {

    }

But i get an error saying:

OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs)': no suitable method found to override

I already cleaned my solution and tried a rebuild...

Any ideas?

Edit2:

So i found out that in WPF .Net 4.5 the OnNavigatedTo event is gone. What i couldnt find out why and how i could call something similiar.

1
You mean the OnNavigatedTo event? - Fred
Yes, but i have troubles handling this event in my ViewModel. Somehow i have to tell the view Model that this event exists and where it comes from. I'm having trouble with that. - Julian
When I use protected override void OnNavigatedTo in my page class ich get an error, that there is no Method with that name to override.... - Julian
Do all the views use the same ViewModel? - ΩmegaMan
No they dont, every View has its own VM - Julian

1 Answers

1
votes

I haven't gotten an answer to my question so I will attempt an answer...

Don't over think this...if one needs to transfer information either create a static link to the VM(s) in question, or set aside a static drop on the app class. Either way when a view is shown, subscribe to one of the initialization/load events and pick up the information at the predetermined location.