WPF DataGridRow Event

CM(Caliburn.Micro)框架绑定DataGridRow事件

1       <DataGrid.ItemContainerStyle>
2                             <Style TargetType="DataGridRow">
3                                 <Setter Property="cm:Message.Attach"
4                                         Value="[Event MouseLeftButtonUp] = [Action RowCheckSetting_MouseLeftButtonUp($source,$eventArgs)];[Event KeyUp] = [Action RowCheckSetting_KeyUp($eventArgs)]" />
5                             </Style>
6        </DataGrid.ItemContainerStyle>

public void RowCheckSetting_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
//todo
}

EventSetter事件方式处理

    <DataGrid.ItemContainerStyle>
                    <Style TargetType="DataGridRow">
                        <EventSetter Event="MouseDoubleClick"
                                     Handler="DataGrid_MouseDoubleClick"></EventSetter>
                        <Setter Property="cm:Message.Attach"
                                Value="[Event MouseDoubleClick] = [Action OnSummaryDataGridMouseDoubleClick($source)]" />
                    </Style>
                </DataGrid.ItemContainerStyle>

Handler对应的事件

  private void DataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {

        }

上面代码使用CM框架和EventSetter方式处理DataGridRow的双击事件,当然也可以使用其他的Click事件。

原文地址:https://www.cnblogs.com/ligl/p/7007489.html