WPF DataGrid double click on + INotifyPropertyChanged?

I want the command in my ViewModel to execute when the DataGrid is clicked. As a parameter, I want to have the corresponding string.

I found one approach on the web, but using DependencyProperty

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/632ea875-a5b8-4d47-85b3-b30f28e0b827

I do not use DependencyProperty in my project, instead I use INotifyPropertyChanged . How to implement "double click in datagrid" commaind without using DependencyProperty ?

+4
source share
4 answers
 xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" ... <DataGrid SelectedItem={Binding MySelectedItem, Mode=TwoWay}> <i:Interaction.Triggers> <i:EventTrigger EventName="MouseDoubleClick"> <i:InvokeCommandAction Command="{Binding YourCommand}" /> </i:EventTrigger> </i:Interaction.Triggers> </DataGrid> 
+8
source

I usually use AttachedCommandBehavior . These are 3 cool files that can be added to your project, and allows you to attach teams to almost any event.

Here is an example of how to use it:

 <Style TargetType="{x:Type DataGridRow}"> <Setter Property="local:CommandBehavior.Event" Value="MouseDoubleClick" /> <Setter Property="local:CommandBehavior.Action" Value="{Binding MyDoubleClickCommand}" /> <Setter Property="local:CommandBehavior.CommandParameter" Value="{Binding }" /> </Style> 
+3
source

The MVVM Light Toolkit provides the EventToCommand behavior, it should be able to achieve the desired behavior (you can always flip your own, you want to use the framework).

+2
source

You can use this snapshot code to identify a row that is double clicked.

In the line with the comment "// do something with the underlying data", you can get the connected ViewModel from the Grid or DataContext row and call your command with the row parameter as a parameter.

0
source

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


All Articles