• WPF 新窗口点击按钮修改另一个窗口的控件属性


    先描述一下我遇到的问题:我有个主窗口,里面有一些按钮是设置不可用状态,还有一个按钮点击可以打开新窗口StartGameWindow,在新窗口点击按钮关闭后,主窗口那些不可用状态的按钮变为可用状态。
    我的解决方法:
    1、主窗口Mainwindow.xaml.cs

    private void StartGame_Click(object sender, RoutedEventArgs e)
    {
                StartGameWindow startGameWindow = new StartGameWindow();
                startGameWindow.Owner = this;
                startGameWindow.ShowDialog();
    }
    
    

    这一步设置主窗口为owner
    2、窗口StartGameWindow.xaml.cs

    private void GameStart_Click(object sender, RoutedEventArgs e)
    {
                MainWindow mainWindow = new MainWindow();
    
                (this.Owner as MainWindow).NextDay.IsEnabled = true;
                (this.Owner as MainWindow).Save.IsEnabled = true;
    
                this.Close();
    }
    

    点击关闭后按钮就变活跃状态了
    如果你觉得我这篇博客有用的话,点个赞吧~

  • 相关阅读:
    RequestMapping_PathVariable注解
    RequestMapping_Ant 路径
    RequestMapping_请求参数&请求头
    RequestMapping_请求方式
    RequestMapping注解_修饰类
    18)C++对C的增强
    17)C++开始--命名空间
    16)未理解透
    15)文件函数例子
    14)文件操作
  • 原文地址:https://www.cnblogs.com/AlinaL/p/12852130.html
Copyright © 2020-2023  润新知