使用了如下所示的事件触发器,
<i:Interaction.Triggers>
<local:EventTriggerExt EventName="MouseLeftButtonDown">
<i:InvokeCommandAction Command="{Binding BuyItemCommand}" />
</local:EventTriggerExt>
<local:EventTriggerExt EventName="MouseRightButtonDown">
<i:InvokeCommandAction Command="{Binding SellItemCommand}" />
</local:EventTriggerExt>
</i:Interaction.Triggers>
代码背后:
class EventTriggerExt :System.Windows.Interactivity.EventTrigger
{
protected override void OnEvent(EventArgs eventArgs)
{
if(this.AssociatedObject is SfDataGrid && eventArgs is MouseButtonEventArgs)
{
var args = eventArgs as MouseButtonEventArgs;
}
base.OnEvent(eventArgs);
}
}
当我点击DataGrid Cell时,MouseRightButtonDown事件与SellItemCommand配合得很好。但MouseLeftButtonDown事件不起作用,也适用于LeftClick事件。希望任何人都面对这一点,并提出相同的解决方案。
有什么想法吗?
此致 Smirti
答案 0 :(得分:0)
MouseLeftButtonDown
单元格,则不会触发 DataGrid
事件。这是因为SelectionChanged
事件将在MouseLeftButtonDown
之前被调用,之后它将不会使事件冒泡。如果单击DataGrid的其他部分而不是单元格,例如在最后一列之后的空白区域,您会注意到正在调用MouseLeftButtonDown
。
而不是&#39; MouseLeftButtonDown
&#39;您可以使用PreviewMouseLeftButtonDown
之前调用的SelectionChanged
事件。