2013-09-28 121 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元素必須是根元素 - 它不能是另一個控件的孩子。您可以打開來自另一個控件的窗口,但無法使窗口成爲另一個控件的內容。