开发者

WPF - Control 2nd window from 1st window

开发者 https://www.devze.com 2023-01-28 09:47 出处:网络
WPF - From Window1 I\'m trying to maximize a previously minimized Window2. This is how I am opening Window2 (I hope to use the same button to maximize it)

WPF - From Window1 I'm trying to maximize a previously minimized Window2.

This is how I am opening Window2 (I hope to use the same button to maximize it)

 public partial class Window1 : Window
{

    private bool SecondWindowOpen = false;

    public Window1()
    {
        InitializeComponent();
    }

    private void OpenSecondWindow_Click(object sender, RoutedEventArgs e)
    {
        if (SecondWindowOpen == false)
        {
            new Window2().Visibility = Visibility.Visible;
            th开发者_开发知识库is.SecondWindowOpen = true;

        }

        else
        {


        }
    }
}

Window2 has 2 buttons, one minimizes Window2 while the other closes it.

public partial class Window2 : Window
{
    public Window2()
    {
        InitializeComponent();
    }

    private void btnMinimize_Click(object sender, RoutedEventArgs e)
    {
        this.WindowState = WindowState.Minimized;
    }

    private void btnClose_Click(object sender, RoutedEventArgs e)
    {
        Close();
    }
}

So after opening Window2, I click btnMinimize. Now I'm back in Window1 and would like to click OpenSecondWindow and return Window2 to its original position. I would think this is a syntax issue, but I have been unable to find any examples.

Thank You


public partial class Window1 : Window
{

    private bool SecondWindowOpen = false;
    private Window2 window2;

    public Window1()
    {
        InitializeComponent();
    }

    private void OpenSecondWindow_Click(object sender, RoutedEventArgs e)
    {
        if (SecondWindowOpen == false)
        {
            window2 = new Window2();
            window2.Visibility = Visibility.Visible;
            this.SecondWindowOpen = true;
        }
        else
        {
            //do whatever you want with window2, like window2.Close();
            //or window2.Visibility = Visibility.Hidden;
        }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消