2013-09-28 123 views
1

如何从桌面WPF应用程序的页面导航到新页面或Window。我曾尝试以下调用Windows的页面,但我得到的错误:从桌面WPF应用程序的页面导航到新页面或窗口

Window must be the root of the tree. Cannot add Window as a child of Visual

private void btCode_Click(object sender, RoutedEventArgs e) 
{ 
    CodeView window = new CodeView(cbRe.Text, txtID.Text); 
    this.Content = window; 
} 

当我修改代码来调用一个新的页面,我收到了类似的错误说法页面必须从Window调用。

回答

0

页打开一个窗口

myWindow w = new myWindow(); 
     w.Show(); 

导航到一个新的页面

myPage p = new myPage(); 
     myFrameInCurrentWindow.Navigate(p); 
0

由于错误状态时,Window元素必须是根元素 - 它不能是另一个控件的孩子。您可以打开来自另一个控件的窗口,但无法使窗口成为另一个控件的内容。