【问题标题】:MouseLeftButton event doesnt gets triggered when used with Custom Event Trigger与自定义事件触发器一起使用时不会触发 MouseLeftButtonup 事件
【发布时间】:2016-04-07 05:37:44
【问题描述】:

已经使用了如下的事件触发器,

<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 单元格时,MouseRightButtonDown 事件与 SellItemCommand 配合得很好。但是 MouseLeftButtonDown 事件不起作用,LeftClick 事件也不起作用。希望任何人都遇到过这个问题并提出解决方案。

有什么想法吗?

问候, 斯米尔蒂

【问题讨论】:

    标签: c# wpf events triggers


    【解决方案1】:

    如果您单击DataGrid 单元格,则不会触发MouseLeftButtonDown 事件。这是因为SelectionChanged 事件将在MouseLeftButtonDown 之前调用,之后它不会冒泡事件。如果您单击单元格以外的 DataGrid 的其他部分,例如最后一列之后的空白处,您会注意到正在调用MouseLeftButtonDown

    因此,您可以使用PreviewMouseLeftButtonDown 事件代替“MouseLeftButtonDown”,该事件将在SelectionChanged 之前调用。

    【讨论】:

    • PreviewMouseLeftButtonDown 在我这边不起作用。已经尝试过Leftclick事件。它也不起作用。还有其他方法吗?
    猜你喜欢
    • 1970-01-01
    • 2012-06-08
    • 1970-01-01
    • 1970-01-01
    • 2015-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-09
    相关资源
    最近更新 更多