在样式中定义输入绑定。

7

我希望在 Style 中的每个 ListBoxItem 中都添加右键和左键命令,这可能吗?

<Style TargetType="{x:Type ListBoxItem}">
    <Setter Property="InputBindings">
        <Setter.Value>
            <MouseBinding Command="{x:Static View:Commands.AddItem}"
                          MouseAction="LeftClick"/>
            <MouseBinding Command="{x:Static View:Commands.RemoveItem}"
                          MouseAction="RightClick"/>
        </Setter.Value>
    </Setter>
</Style>

这个回答解决了你的问题吗?在样式中定义InputBindings - StayOnTarget
1个回答

2

我最初想要实现的目标没有找到方法。最终我使用了事件而不是命令。

<Style TargetType="{x:Type ListBoxItem}">
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="AssignItem"/>
<EventSetter Event="PreviewMouseRightButtonDown" Handler="RemoveItem"/>
</Style>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接