0

In a Modern UI for Wpf (MUI) application, I would like to navigate to a specific instance of an existing page, e.g.:

Page myPageInstance = new Page();
NavigateTo(myPageInstance);

but all available methods, like:

NavigationCommands.GoToPage.Execute("/Pages/Page.xaml", this);

or:

NavigationService nav = NavigationService.GetNavigationService(this);
nav.Navigate(myPageInstance)

or:

NavigationWindow nav = FindAncestor<NavigationWindow>(this);

...

    public static T FindAncestor<T>(DependencyObject dependencyObject) where T : DependencyObject
    {
        var parent = VisualTreeHelper.GetParent(dependencyObject);

        if (parent == null) return null;

        var parentT = parent as T;
        return parentT ?? FindAncestor<T>(parent);
    }

do not work (the earlier creates a new page instance, the second doesn't find any NavigationService (nav is null), the latter doesn't find any NavigationWindow (of course, as the root is a FirstFloor.ModernUI.Windows.Controls.ModernWindow))

Any suggestion?

Thanks!

Starnuto di topo
  • 3,215
  • 5
  • 32
  • 66
  • 1
    Why do you want to navigate to a specific instance of a view? If using MVVM pattern correctly, your data will be stored in ViewModel classes and the view instance should not matter. Let the application manage the lifetime of the view for you. – Glen Thomas Aug 04 '15 at 08:17
  • Navigation in the WPF works with [`Frame`](https://msdn.microsoft.com/en-us/library/system.windows.controls.frame(v=vs.110).aspx) element. – Hamlet Hakobyan Aug 04 '15 at 08:18
  • Yes, I ended up creating my implementation of IContentLoader, so that when a Uri is requested, an instance of the viewModel is associated to the view – Starnuto di topo Aug 04 '15 at 10:03
  • 1
    How did you solve the problem with getting a NavigationWindow in MUI? I have the same problem! – Johan Danforth Aug 13 '15 at 13:44
  • As I said, I implemented IConrentLoader (search for it on the net). Though, I was not very happy of the whole framework, so I finally moved to http://mahapps.metro/ – Starnuto di topo Aug 14 '15 at 17:47

0 Answers0