这是模板:
//Button Opens and Closes 'Basic Arithmetic' Window.
private void Button_Click(object sender, RoutedEventArgs e)
{
Window1 BasicArithmetic = new Window1();
if (BasicArithmetic.IsActive == false)
{
BasicArithmetic.Show();
}
else
{
BasicArithmetic.Close();
}
}
此代码成功打开窗口,但未关闭窗口...
你能想到对if语句更好的测试吗?
请帮助:')
答案 0 :(得分:0)
感谢 @ daniel.shih 我能够弄明白,这是工作代码:
Window1 BasicArithmetic = new Window1();
//Button Opens and Closes Basic Arithmetic Window
private void Button_Click(object sender, RoutedEventArgs e)
{
if (BasicArithmetic.IsVisible == false)
{
BasicArithmetic.Show();
}
else
{
BasicArithmetic.Hide();
}
}
我按照 @ daniel.shih
的建议,将Window1
行移到点击事件之上
我将IsActive
测试更改为IsVisible
我将.Close()
更改为.Hide()