开发者

WPF - Catch a CLR event in A Style template

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开发者_JAVA百科 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜