Lets say for example we have a single WPF window with 2 tabs and a file menu. The file menu has two items "Hide Tab 1", "Show Tab 1"
The program then has the following classes: MainView.xaml
MainViewModel.cs
"Hide tab 1" is bound to HideTab1Command which is contained within MainViewModel.cs
HideTab1 then directly interacts with the View to hide tab1 from within the ViewModel.
Is this technically not MVVM behaviour (more like MVP)? Eg for true MVVM the functionality to perform this behavior should be contained entirely in XAML code or in "code behind" within MainView.xaml.cs ?
I see MVVM applications and examples that do this all the time, however it seems to break the SRP (Single Responsibility Principle).
I see some other applications that do the same with the HideTab1 command simply notifying the view via an interface IMainView which then calls code within MainView.xaml.cs
Whilst I can see that the code is now within the View how is this really any different from the first example. The SRP is still voided with the ViewModel telling the View what to do.
Are either of these examples true MVVM patterns and if not what would be the correct MVVM pattern to achieve hiding/showing "tab 1"
Aucun commentaire:
Enregistrer un commentaire