从桌面 WPF 应用程序中的页面导航到新页面或窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19067266/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
navigate to a new page or window from a page in a desktop WPF application
提问by user2631662
How can I navigate to a new page or Windowfrom a page in a desktop WPF application. I have tried the following to call the windows page, but I get the error:
如何导航到新页面或Window从桌面 WPF 应用程序中的页面导航。我尝试了以下方法来调用 windows 页面,但出现错误:
Window must be the root of the tree. Cannot add Window as a child of Visual
窗口必须是树的根。无法将 Window 添加为 Visual 的子项
private void btCode_Click(object sender, RoutedEventArgs e)
{
CodeView window = new CodeView(cbRe.Text, txtID.Text);
this.Content = window;
}
When I alter code to call a new page I get a similar error saying page must be called from a Window.
当我更改代码以调用新页面时,我收到类似的错误消息,指出必须从Window.
采纳答案by user2631662
Page opening a Window
页面打开窗口
myWindow w = new myWindow();
w.Show();
Navigating to a new page
导航到新页面
myPage p = new myPage();
myFrameInCurrentWindow.Navigate(p);
回答by Ming Slogar
As the error states, the Windowelement must be the root element - it cannot be a child of another control. You can opena window from another control, but you cannot make a window the content of another control.
正如错误所述,该Window元素必须是根元素 - 它不能是另一个控件的子元素。您可以从另一个控件打开一个窗口,但不能使一个窗口成为另一个控件的内容。
回答by Alberto
Take a look at the navigation features of wpf: http://msdn.microsoft.com/en-us/library/ms750478.aspx
看看wpf的导航功能:http: //msdn.microsoft.com/en-us/library/ms750478.aspx

