简体   繁体   English

如何从窗口调用 xaml 页面? (WPF)

[英]How to call an xaml page from a window? (WPF)

I'm a beginner at WPF so it might be a silly question.我是 WPF 的初学者,所以这可能是一个愚蠢的问题。

To call one page from page, I have done something similar to the following code:要从页面调用一页,我做了类似于以下代码的操作:

 private void Button_Click(object sender, RoutedEventArgs e)
 {
     NavigationService.Navigate(new Uri("/ProductsManagement.xaml", UriKind.Relative));
 }

But now I have created a Window and when trying to execute the previous code an error is generated.但是现在我已经创建了一个 Window 并且在尝试执行之前的代码时会生成一个错误。 Any suggestions or comments are welcome.欢迎任何建议或意见。

The error:错误:

在此处输入图片说明

With solution:有解决方案:

在此处输入图片说明

Solution:解决方案:

NavigationWindow _navigationWindow = new NavigationWindow();

_navigationWindow.Height = this.Height;
_navigationWindow.Width = this.Width;
_navigationWindow.Show();

_navigationWindow.Navigate(new MyPageXML());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM