c# - 如何更改另一个类中的“框架内容”?(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(); }
我将不胜感激任何有用的提示,因为昨天我花了几个小时在互联网上寻找,却一无所获。
解决方案
尝试这个:
private void bttn_start(object sender, RoutedEventArgs e)
{
MainWindow mw = (MainWindow)Application.Current.MainWindow;
mw.JoinNextPage();
}
推荐阅读
- elasticsearch - 尝试为定义的 Elasticsearch 模板中缺少的字段建立索引
- php - 在 php 中注销时出现 500 内部服务器错误
- laravel - laravel 中的更新方法问题(不支持 POST 方法)
- angular - 如何获取打字稿对象的属性
- python - 在 .insert_picture() 之后访问 python-pptx 图片占位符时出错
- python - 如何将推荐 Keras 模型从 Tensorflow 示例导出到 tflite?
- reactjs - 使用 react-spring,如何在不提供“from”值的情况下使用“useSpring()”进行动画处理?
- java - 如何使用通用方法获取实例
- android - 如何在 android sharesheet 中显示应用程序的多个活动?
- javascript - obj1 在深度比较算法中未定义