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

How to handle a double-click on a grid row in a MVVM application

$
0
0

This example demonstrates one of many possible solutions for decoupling DXGrid mouse event handling from business logic, when using the MVVM architectural pattern.

Question Comments

Added By: Gert Hauan at: 1/26/2015 2:08:55 AM    

Hi

I am trying to get this to work, but without success. The reason is possibly the way that MVVM is implemented in the application I am working on. It is different from the way you have done it.

If I understand your code correctly, you have one viewmodel object pr row in the datagrid. In the application I am working on, there is one viewmodel for the whole view, that is the viewmodel is the datacontext of the view. Then the ItemsSource of the datagridcontrol is bound against a collection in the viewmodel.

Basicly what I would like to do is this: Today there is a button under the gridcontrol called "Open". This button is bound to a command in the viewmodel that opens a new (PRISM)view based on the FocusedRow. I need that same command to fire when a row is doubleclicked. Could you help me along the way here?

(It is difficult to post an example project due to the size of the app.)

Added By: Alexander (DevExpress Support) at: 1/26/2015 8:26:33 AM    

Hi Gert,

This is old example. Now, we have the MVVM Framework that allows doing such things with ease. I suggest you use the EventToCommand with an EventArgsConverter in the following manner:

[XAML]
<dxg:GridControlName="gridControl"...><dxmvvm:Interaction.Behaviors><dxmvvm:EventToCommandPassEventArgsToCommand="True"Command="{Binding EditCommand}"EventName="MouseDoubleClick"><dxmvvm:EventToCommand.EventArgsConverter><dx:EventArgsToDataRowConverter/></dxmvvm:EventToCommand.EventArgsConverter></dxmvvm:EventToCommand></dxmvvm:Interaction.Behaviors> ...</dxg:GridControl>

You can see how this code operates in the How to build a fully-functional and well-organized MVVM application in a few clicks with DevExpress components (Visual Studio 2012+) example (file - EmployeeCollectionView.xaml).

Added By: Gert Hauan at: 1/27/2015 12:59:56 AM    

Hi

Do you know if I may use  this functionality from your MVVM Framework in conjunction with the PRISM framework?

(FYI: I was able to get the double-click to work by using this approach: https://www.devexpress.com/Support/Center/Question/Details/Q534762 )

Added By: Alexander (DevExpress Support) at: 1/27/2015 1:30:09 AM    

Our MVVM Framework consists from independent parts that can be used with any other third-party framework. 


Viewing all articles
Browse latest Browse all 7205

Trending Articles



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