Beetlejuice
Beetlejuice

Reputation: 4425

Bind same command to datagrid double click

I have a menu item that is configured to execute a command using binding:

<MenuItem Margin="2" 
     Header="Process something"
     Command="{Binding SomethingCommand}" 
     IsEnabled="{Binding SomethingIsEnabled}">
</MenuItem>

It also configure if this item is enabled or not.

Now, I need to execute the same command when user double click a row in datagrid and only when "SomethingisEnabled" is true.

How to configure datagrid to do that?

Upvotes: 0

Views: 59

Answers (1)

Kevin Cook
Kevin Cook

Reputation: 1932

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

<DataGrid x:Name="dataGrid" ItemsSource="{Binding DataList}">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseDoubleClick">
                    <i:InvokeCommandAction Command="{Binding SomethingCommand}" CommandParameter="{Binding ElementName=dataGrid, Path=SelectedItem}"></i:InvokeCommandAction>
                </i:EventTrigger>
            </i:Interaction.Triggers>
</DataGrid>

This will call a relaycommand SomethingCommand and pass the selected item (if any, otherwise null) on the doubleclicked grid.

Upvotes: 2

Related Questions