首页 > 解决方案 > 如何更改另一个类中的“框架内容”?(C# WPF XAML)

问题描述

有一次解释一下,我通过“frame.content”打开了一个 xaml 页面,在我打开的这个页面中,我想打开另一个页面,但是在第二个页面正在运行的框架上。但我无法打开页面,

什么都没发生。甚至没有期望。

所以这里是我写的:


这是打开的页面中的类

private void bttn_start(object sender, RoutedEventArgs e)
{
   MainWindow mw = new MainWindow();
   mw.JoinNextPage();
}

这是框架所在的 MainWindow 类。

public partial class MainWindow : Window
{ 
   public void JoinNextPage() => pageMirror.Content = new page_finish();
}

我将不胜感激任何有用的提示,因为昨天我花了几个小时在互联网上寻找,却一无所获。

标签: c#wpfxamlmvvm

解决方案


尝试这个:

private void bttn_start(object sender, RoutedEventArgs e)
{
   MainWindow mw = (MainWindow)Application.Current.MainWindow;
   mw.JoinNextPage();
}

推荐阅读