WPF root element is not valid for navigation

后端 未结 3 806
天命终不由人
天命终不由人 2021-01-03 04:50

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.



        
相关标签:
3条回答
  • 2021-01-03 05:11

    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 };
        }
    
    0 讨论(0)
  • 2021-01-03 05:30

    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.

    0 讨论(0)
  • 2021-01-03 05:37

    please check StartForm having the page as root element or some other else. I am having the same. I have check the page which has to be navigated. I declare that page as window.

    0 讨论(0)
提交回复
热议问题