[英]How to trigger an event when a variable gets the same value in a specified timeframe?
[英]MouseLeftButton event doesnt gets triggered when used with Custom Event Trigger
使用了如下的事件触发器,
<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
如果您单击DataGrid
单元格,将不会触发MouseLeftButtonDown
事件。 这是因为SelectionChanged
事件将在MouseLeftButtonDown
之前被调用,此后将不会冒泡该事件。 如果单击DataGrid而不是单元格的其他部分(例如,最后一列之后的空白),则会注意到正在调用MouseLeftButtonDown
。
因此,可以使用PreviewMouseLeftButtonDown
事件而不是' MouseLeftButtonDown
'事件,该事件将在SelectionChanged
之前调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.