0
votes

Here is the problem. I am using MVVM on a WPF project and using MVVM light. I have a grid in a user control that returns results from a search. I want the users to be able to click on the grid and have the row available for the parent view to use (from a menu) and have it so users can double click on the row and open in a new "window". Individually I have these items work properly, however I can not get both to work. I am trying to tie 1 command to the MouseUp and another to MouseDoubleClick but the MouseDoubleClick event never gets fired. How can I be able to use the mouseUp and MouseDoubleClick events in a MVVM setup? or any other suggestions to be able to select a row from the datagrid to be available to menu items and to be able to doubleclick on.

3
I have figured out part of this. In the WPF Datagrid you can determine if there was a single click or more by checking the MouseLeftButtonDown e.ClickCount. If single click then it is 1 otherwise it is 2 or more. See msdn.microsoft.com/en-us/library/… for more information. This works in a normal project, but the click count appears off (delayed?) when using MVVM. Maybe someone else can help point in the right direction?Consulting Mechanic

3 Answers

1
votes

Using MVVMLight the eventtocommand will get you selectionchanged and mousedoubleclicked events.

0
votes

I think you're going to have to manually detect a double-click.

dblClickTimeOut = null;
row.onmouseup = function() {
    if( dblClickTimeOut == null)
        dblClickTimeOut = setTimeout("dblClickTimeOut = null; selectRow('"+this.id+"');",200);
    else {
        // double-click stuff
    }
}
selectRow = function() {
    // single-click stuff
}
0
votes

For those who love short ways (also mvvm friendly!), define the interactivity in your xaml-class:

xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"

And in your Grid:

<Grid>
  <Grid.InputBindings>
     <MouseBinding MouseAction="LeftDoubleClick" Command="{Binding ElementName=xyz, Path=DataContext.MouseDoubleClick}"/>
  </Grid.InputBindings>
  <i:EventTrigger EventName="MouseUp">
     <cmd:EventToCommand Command="{Binding ElementName=xyz, Path=DataContext.MouseUpEvent}"/>
  </i:EventTrigger>
</Grid>

Hope that helps.