WPF root element invalid for navigation

I am converting a WPF XBAP application to a WPF desktop application. This works for me on the desktop, but now I'm trying to change links to Window links.

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

I tried to create a simple version of this application and convert it, and it works fine, so there should be something in XAML that calls this when using Window tags. My question is how I can investigate this. Currently, all I get is an error, followed by a "No Source" screen; stack locations are not shown, and Show Disassembly does not work. Besides systematically commenting on individual XAML fragments while it doesn't work, is there any way to decide what this problem is?

+3
source share
3 answers

Navigation in a WPF application can only be done between pages. The error appears because you are trying to “switch” to what is now a window, and this is not possible.

Instead of converting your page into a window, create a new window with a control Frame. A Framecan be used to host your existing pages - which should remain as they are and should not be replaced with Windows.

+5
source

It’s not entirely accurate that it is impossible to place 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 };
    }
+5
source

, , StartForm - . . , . .

0
source

All Articles