繁体   English   中英

与自定义事件触发器一起使用时,不会触发MouseLeftButton事件

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM