【问题标题】:How to bind delete to action in Caliburn.Micro WPF?如何将删除绑定到 Caliburn.Micro WPF 中的操作?
【发布时间】:2020-05-04 20:51:32
【问题描述】:

我目前正在尝试在删除数据网格行时将“delete”键绑定到Action

设置KeyBinding 似乎不起作用:

<DataGrid.InputBindings>
    <KeyBinding Key="Delete"
                cal:Message.Attach="[Key Delete] = [Action DeletePartNumberRow()]"/>
</DataGrid.InputBindings>

将其设置为DataGrid,也不起作用:

<DataGrid x:Name="PartNumbers"
          CanUserAddRows="True"
          CanUserDeleteRows="True"
          cal:Message.Attach="[Gesture Delete] = [Action DeletePartNumberRow()]">
...
</DataGrid>

我想知道是否有其他方法可以做到这一点,或者我是否尝试了错误的方式?

最终我希望能够在应用程序中创建自定义键绑定。我还有其他方法可以做到这一点吗?

【问题讨论】:

    标签: wpf data-binding caliburn.micro


    【解决方案1】:

    您可以通过从 System.Windows.Interactivity.TriggerBase 派生来做到这一点:

    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    
    <i:Interaction.Triggers>
        <common:InputBindingTrigger>
            <common:InputBindingTrigger.InputBinding>
                <KeyBinding Key="Delete"/>
            </common:InputBindingTrigger.InputBinding>
            <cal:ActionMessage MethodName="DoTheMagic"/>
        </common:InputBindingTrigger>
    </i:Interaction.Triggers>
    

    你在网上有很多样本,例如HERE

    【讨论】:

    • 谢谢,确实有效。知道如何设置可以编辑/更改的全局自定义键盘快捷键吗?
    • 什么意思如何设置?如果它的问题是......每个动作的每个关键......(对不起我的英语不好)
    • 也许通过查看转换器...但在这种情况下永远不要测试它...stackoverflow.com/questions/5016457/…stackoverflow.com/questions/3625859/…
    • 再次感谢。我认为这将引导我走向正确的方向。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-26
    • 2012-03-13
    • 1970-01-01
    • 2014-08-13
    • 2015-11-05
    • 1970-01-01
    相关资源
    最近更新 更多