【发布时间】:2009-12-11 17:25:13
【问题描述】:
我有一个ListBox 的风格。在ListBox 样式中,我有一个ListBoxItems 的样式。所有这些都在该部分中。
我想捕捉列表框项的IsEnabledChanged 事件(请参阅this question 了解原因)。我尝试设置EventSetter,但它看不到该事件,因为它不是“路由事件”。
如何将事件附加到此模板项目? (请记住,它本身并不附加到特定的ListBox。它是
这里有一些示例代码来说明我在说什么。
<Style x:Key="CheckBoxListStyle" TargetType="ListBox">
<Style.Resources>
<Style TargetType="ListBoxItem">
<EventSetter Event="IsEnabledChanged" Handler="OnEnabledChanged"\>
.... ^
|
This is not allowed ------
找不到这个事件。试图获得更具体的ListBoxItem.IsEnabledChanged 没有帮助。
编辑: 我不打算在 XAML 中执行此操作。如果有其他方法可以通过后面的代码来做到这一点,那也一样好。我只是不知道如何从后面的代码中访问资源模板。
【问题讨论】:
-
我在尝试移动 WPFToolkit 提示和技巧页面的 DataGrid 中显示的代码以在资源字典中定义的样式中工作时遇到了同样的问题。 wpf.codeplex.com/…
标签: wpf events templates styles