Handling navigation events by bound commands?

Oct 26, 2014 at 12:22 PM
Edited Oct 26, 2014 at 12:26 PM
Hello all,

I'm working on an m:ui application where I want to select an entity to display from the links in a list layout page. I want to use only one view and one viewmodel. From the documentation I understand that I should implement the IContent interface on the view and handle the OnFragmentNavigation event to tell the viewmodel which data to supply. So far so good!

Now I'm trying to avoid code-behind wherever possible so the solution provided by "MuiContentControl" in this post combined with MVVMLights "EventToCommand" seemed to be the perfect solution.
        <i:EventTrigger EventName="FragmentNavigation">
            <cmd:EventToCommand Command="{Binding FragmentNavigationCommand}" PassEventArgsToCommand="True"/>
However, since the "FragmentNavigation" event handler isn't set up the first time the view is navigated to the command isn't executed the first time the page is displayed. My question is: Is there a good way to handle this (maybe creating the view before actually being navigated to) or should I just take the easy way out and use the code-behind this time?

Thanks in advance!

// Magnus