views:

251

answers:

1

I have a style for a ListBox. In the listbox style I have a style for the ListBoxItems. All of this is in the section.

I want to catch the IsEnabledChanged event for the Listbox Items (see this question for why). I tried setting up an EventSetter, but it can't see the event because it is not a "routed event".

How can I attach an event to this templated item? (Remember it is not attached to a specific Listbox per-se. It is a style in

Here is some sample code to show what I am talking about.

<Style x:Key="CheckBoxListStyle" TargetType="ListBox">
    <Style.Resources>
        <Style TargetType="ListBoxItem">
            <EventSetter Event="IsEnabledChanged" Handler="OnEnabledChanged"\>
            ....                     ^ 
                                     |
            This is not allowed ------

It can't find this event. Trying to get more specific (ListBoxItem.IsEnabledChanged) does not help.

Edit: I am not set on doing this in the XAML. If there is some other way to do this via the code behind that would be just as good. I just don't know how to get access to the resources templates from code behind.

+1  A: 

Unfortunately an EventTrigger will only work on RoutedEvents (MSDN), it is not possible to use a CLR event in this case.

From the article:

...while EventTrigger objects start a set of Actions when a specified routed event occurs.

Ben Collier
Is there some other way to get that event for my templated item?
Vaccano