Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

How to handle GridControl's events at the ViewModel level using the EventToCommand extension from MVVM Framework

$
0
0

MVVM Framework provides a powerful EventToCommand feature that allows delegating event processing logic to the ViewModel level. This example illustrates how to use this functionality to process DXGrid events.

 

The EventToCommand class provides the PassEventArgsToCommand option that allows passing the corresponding EventArgs as a command parameter. However, it is not good MVVM practice (even though it might be necessary in certain cases) to make a ViewModel aware of event arguments. It is better to extract necessary information from event arguments and then pass this information as a command parameter. To do this, use EventArgsConverter.

 

So, this example demonstrates the following cases:

1) How to invoke a command from a ViewModel when an event is raised. In this example, the built-in BestFitColumns command is invoked when the View's Loaded event is triggered.

 

2) How to invoke a command from a ViewModel when an event is raised and pass event arguments as a command parameter. This approach is used to delegate processing the ShowingEditor event to the ViewModel level.

 

3) How to invoke a command from a ViewModel when an event is raised, extract necessary information from event arguments using a Converter and then pass it as a parameter. The View's MouseDoubleClick and FocusedColumnChanged events are processed in this manner.

 

Note this approach can be used for other controls as well. This example also illustrates how to process a BarItem's ItemDoubleClick event in this manner.

To implement similar functionality in Silverlight, see T245878.


Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>