Member 'FormWindowState.Minimized' cannot be accessed with an instance reference

508 Views Asked by At

I am trying to call this method from another class.

    public void minimize()
    {
        System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
        {             
            var min = new MainWindow();
            min.WindowState = WindowState.Minimized;
        }));
    }

But I get this error:

Member 'FormWindowState.Minimized' cannot be accessed with an instance reference; Qualify it with a type name instead

How can I solve the issue?

1

There are 1 best solutions below

0
On

I figured the error: What I was trying to do is to access the state of an undefined window. What needed to be done is to get the current window through the GetWindow() method and then set the WindowState of the current window as minimized. Here the full code

var min = new MainWindow();
Window window = Window.GetWindow(min);
Application.Current.MainWindow.WindowState = WindowState.Minimized;