I'm trying to bind the Window's Width and Height using MVVM.
In my ViewModel i declare this Property:
public Size WindowSize
{
get => _windowSize;
set
{
_windowSize = value;
OnPropertyChanged();
}
}
In my XAML i put this:
<Window
Width="{Binding WindowSize.Width, Mode=TwoWay}"
Height="{Binding WindowSize.Height, Mode=TwoWay}"
...>
If i first intialize it like WindowSize = new Size(100, 600);
it works, but if i do the same at a later point in my ViewModel Code it only changes the Window's Width. I subscribed to the OnSizeChanged Event of the Window and found out that it is only called once when i set the Size and in the SizeChangedEventArgs only the NewSize.Width Property is updated. If i remove the Width Binding it works for the Height again. So it seems it fails to recognize a second Width or Height change. I already tried using two properties, one for width and one for height, but the behavior stayed the same.
Any idea what i'm doing wrong?