RoutedUICommand inside MVVM

I am struggling with MVVM in my application. I have a TabControl, each tab has a control that allows you to somehow edit the file. For example, text files or images. Each control is bound to a class from the ViewModel area (as shown in the diagram). I also have RoutedUICommands. One of these commands is WordWrap and only makes sense in the case of text files. This command is used in MenuItem or Button, etc. I would like to enable it only if the purpose of this command is text management. How to do it in accordance with MVVM?

More details:

chart image

XAML for the window has:

<Window.CommandBindings>
<CommandBinding Command="local:EditorCommands.WordWrap"
    Executed="WordWrapExecuted"
    CanExecute="CommandCanBeExecutedWhenAnythingIsOpen"/>
</Window.CommandBindings>

The menu item is used as follows:

<MenuItem Command="local:EditorCommands.WordWrap"/>

, Executed CanExecute: Window, , MVVM - , ViewModel.

, . ?

RoutedUICommand ?

+4
1

A RoutedUICommand , , System.Windows.Input.CommandBinding CommandBindings, Execute CommandBinding.

, CommandBinding , .

ICommand , MVVM. , MvvmLight RelayCommand: https://msdn.microsoft.com/en-us/magazine/dn237302.aspx.

RelayCommand MVVM Light

DelegateCommand: https://www.codeproject.com/Articles/1055060/DelegateCommand-and-CompositeCommand-in-Prism

MVVM : https://blog.magnusmontin.net/2013/06/30/handling-events-in-an-mvvm-wpf-application/

+1

Source: https://habr.com/ru/post/1668374/


All Articles