先描述一下我遇到的问题:我有个主窗口,里面有一些按钮是设置不可用状态,还有一个按钮点击可以打开新窗口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();
}
点击关闭后按钮就变活跃状态了
如果你觉得我这篇博客有用的话,点个赞吧~