Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define InputBindings in Style

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>
like image 633
jdot Avatar asked Dec 31 '09 01:12

jdot


1 Answers

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>
like image 126
jdot Avatar answered Sep 19 '22 22:09

jdot