Binding the “WindowState” property of a window in WPF using MVVM

后端 未结 3 1066
盖世英雄少女心
盖世英雄少女心 2021-01-12 06:01

I bound the \"WindowState\" property of my main window to my ViewModel in order to change the state of the window by a command, but the first time I minimize the window it m

3条回答
  •  猫巷女王i
    2021-01-12 06:24

    I don't think you should care about the window state in a view model, it's completely wrong because a lower-level layer is aware of a higher-level layer (thus wrong Separation of Concerns (SOC)).

    What I normally do in this case is subscribe to changes in the view model from the code-behind of the control or window (thus the view) containing the view model. In this case, it is valid to write code in the code-behind because it is only used in the view (and thus the code-behind is the perfect location for this logic, which you really don't want to unit test).

提交回复
热议问题