WPF root element is not valid for navigation

17,517

Solution 1

Navigation in a WPF application can only be done between pages. The error shows up because you're trying to "navigate" to what is now a Window, and this isn't possible.

Instead of converting your Page into a Window, create a new Window with a Frame control in it. A Frame can be used to host your existing pages - which should stay exactly as they are, and not be changed into Windows.

Solution 2

Its not entirely accurate about it not being possible to host a window in a frame, the following code will do it for you

    public void HostWindowInFrame(Frame fraContainer, Window win) {
        object tmp = win.Content;
        win.Content = null;
        fraContainer.Content = new ContentControl() { Content = tmp };
    }
Share:
17,517

Related videos on Youtube

Paul Michaels
Author by

Paul Michaels

I've been a programmer for most of my life. I have an interest in games, mobile and tablet development, along with message queuing, and pretty much anything that provides an elegant solution to a problem, technical or otherwise. I like learning new technology and finding new ways to use the old. I blog about my experiences here. You can read about me, or contact me on Linked in here.

Updated on June 13, 2022

Comments

  • Paul Michaels
    Paul Michaels almost 2 years

    I am converting a WPF XBAP app to a WPF desktop app. I have it running on the desktop, but am now trying to change the Page references to Window references.

    'MyApp.StartForm' root element is not valid for navigation.
    

    I have tried creating a simple version of this app and converting that, and this works fine, so there must be something within the XAML that is causing this when using Window tags. My question relates to how I can investigate this. Currently, all I get is this error, accompanied by a "No Source Available" screen; no stack locations are shown and "Show Disassembly" doesn't work. Other than systematically commenting out individual chunks of XAML until it works, is there a way to work out what this issue is?

Related