Reinitialize On Navigation

May 16, 2013 at 12:29 PM
Hello, I'm trying to find the best manner to keep my UI up to date with the DB.

Once the UserControl is loaded it stays into memory, is there a way to force the initialization every time the navigation to a usercontrol gets called.

May 16, 2013 at 12:49 PM
Edited May 16, 2013 at 12:54 PM
Seems I was a bit fast with my question, currently I found this solution:
public partial class MyView: UserControl, IContent
        public MyView()

        public void OnFragmentNavigation(FirstFloor.ModernUI.Windows.Navigation.FragmentNavigationEventArgs e)
            throw new NotImplementedException();

        public void OnNavigatedFrom(FirstFloor.ModernUI.Windows.Navigation.NavigationEventArgs e)
            // do nothing, dataconext already set to null
            // throw new NotImplementedException();

        public void OnNavigatedTo(FirstFloor.ModernUI.Windows.Navigation.NavigationEventArgs e)
            DataContext = new MyViewModel();

        public void OnNavigatingFrom(FirstFloor.ModernUI.Windows.Navigation.NavigatingCancelEventArgs e)
            DataContext = null;
whether its a good one or a good approach is a different question :)
Jun 11, 2013 at 10:47 AM
Created the issue 19838 with this.
Jun 11, 2013 at 5:48 PM
Edited Jun 11, 2013 at 5:48 PM
You can decorate your page with the ModernFrame.KeepAlive=false attached property so that your content is created each time it's requested. See also this discussion
Jun 11, 2013 at 8:32 PM
What can I say!! Just beautiful! Got to see the source code to see more hidden beauties like this!! Having fun doing this!
Jun 12, 2013 at 8:11 AM
ModernFrame.KeepAlive=false makes it very short & nice, already implemented IContent but it does the job too :)