【发布时间】:2019-04-22 18:20:29
【问题描述】:
我有一个自定义 ListBox 控件,其样式在我的 Themes/Generic.xaml 中设置。然后我在 ListBox 的 ItemTemplate 中有一个按钮,它的 Click 事件没有触发,我不知道为什么。按钮的命令(我确信命令问题与 DataContext 无关)和交互触发器也是如此。在尝试调试时,我注意到使用默认 ListBox 而不是我自己的停止了问题,但我需要使用自定义控件。
这基本上就是我所拥有的(为简洁起见,去除了绒毛)。按钮:
<controls:CustomListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<Button Click=MyHandler/>
</DataTemplate>
</ListBox.ItemTemplate>
</controls:CustomListBox>
以及 Themes/Generic 中自定义控件的样式:
<Style TargetType="{x:Type controls:CustomListBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:CustomListBox}">
<Border>
<ScrollViewer Focusable="false" Padding="{TemplateBinding Padding}">
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我怎样才能触发这个事件?
【问题讨论】:
标签: wpf events listbox custom-controls listboxitem