Nevaran
Nevaran

Reputation: 137

Event in Style Resource not firing. Why?

I have a very specific situation where I need to disable focusable in a List Box, but then the items inside it cannot be selected. So I added an EventSetter in the item style to send a notification that it has been clicked so I switch to it behind the scenes, but the event isnt firing up.

Any help in making it work is much appreciated!

Heres the full xaml style code:

<Window.Resources>
    <Style
        x:Key="ListBoxItemStyle"
        BasedOn="{StaticResource {x:Type ListBoxItem}}"
        TargetType="ListBoxItem">

        <Setter Property="Padding" Value="5" />
        <Setter Property="IsTabStop" Value="False" />
        <!--  Fixes spacebar not working and some other bugs if selecting via mouse  -->
        <Setter Property="Focusable" Value="False" />
        <EventSetter
            Event="MouseDown"
            Handler="OnThumbnailSelect" />
    </Style>
</Window.Resources>

Upvotes: 1

Views: 216

Answers (1)

Mark Feldman
Mark Feldman

Reputation: 16119

Use the PreviewMouseDown event instead.

Upvotes: 2

Related Questions