Search code examples
c#wpfwindowfullscreendatatrigger

Window manual minimize override my WindowState setter in DataTrigger


So I've got DataTrigger binded to TriggerButton IsChecked property in my ResourceDictionary.

After button is pressed, window goes full screen.

The problem is, when i manually minimalize window, WindowState is set in code by WPF to minimize and it override my DataTrigger setter, so i can't go full screen again. Is there any way to prevent WPF from override, while leaving functionality of window minimialization?


Solution

  • You could use a property in the code behind instead that updates the WindowState based on a bool property of the checkbox.

    Example:

    public WindowState MainWindowState 
    { 
        get 
        {
            return (IsChecked) ? WindowState.Maximized : WindowState.Normal;
        }
    }
    
    private bool _isChecked;
    public bool IsChecked
    {
        get
        {
            return _isChecked;
        }
        set
        {
            _isChecked = value;
            OnPropertyChanged("IsChecked");
            OnPropertyCHanged("MainWindowState");
        }
    }
    

    This is not a great MVVM approach but it should accomplish what you're trying to do.