WPF:点击时打开和关闭第二个窗口的按钮? (翻开)

时间:2018-02-12 05:40:40

标签: c# wpf user-interface

这是模板:

//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语句更好的测试吗?

请帮助:')

1 个答案:

答案 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()