Define InputBindings in Style
Asked Answered
N

1

7

I would like to add a right click and left click command to each ListBoxItem in a Style. Is this possible?

<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>
Nilson answered 31/12, 2009 at 1:53 Comment(1)
Does this answer your question? Defining InputBindings within a StyleCalabar
N
2

I was not able to find a way to accomplish what I originally wanted. I ended up using Events instead of Commands.

<Style TargetType="{x:Type ListBoxItem}">
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="AssignItem"/>
<EventSetter Event="PreviewMouseRightButtonDown" Handler="RemoveItem"/>
</Style>
Nilson answered 5/1, 2010 at 22:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.