Is EventToCommand a transmission of bad practice from EventArgs?

I recently used MVVM toolkit for Silverlight 4.

I really like the EventToCommand behavior, which is included, it makes life easier. One thing that I was curious about was setting up PassEventArgsToCommand="True"bad practice, as it would bind a specific RelayCommand to a specific event in the view.

eg. If my RelayCommand is defined as:

public RelayCommand<System.Windows.Input.KeyEventArgs> myCommand

Then it can only be triggered by a KeyUp, KeyDown event, etc.

I thought that the ViewModel should not have any user interface knowledge (for example, expose a logical converter and use the converter to change it to Visibility), does not skip EventArgsToCommand, violating this?

+3
source share
3 answers

The ViewModel is the model for the view, so when you refer to a state that must have a view or the data that it must represent, the ViewModel must process it.

One could reasonably use the Visibility enumeration to represent which part of the view should be considered information about the state of the view.

As for KeyEventArgs, this comes from the user's action and represents some state of the command, which, if you need to know which key was pressed, is a reasonable expectation of processing ViewModel.

arg, , unit test .

, Visibility KeyEventArgs - , , ViewModel . , (, , , , , ViewModels).

+1

KeyEventArgs ViewModel, unit test ViewModel, , KeyEventArgs .

, KeyEventArgs Silverlight ( , , ), KeyEventArgs Silverlight.

, unit test. /XAML, EventTrigger KeyDown.

- KeyEventToCommand, XAML. http://mvvmlight.codeplex.com/discussions/252898

+1

ViewModel - "" - , . MVVMLight Messenger .

Hh, indyfromoz

0
source

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


All Articles