【发布时间】:2011-10-19 18:32:20
【问题描述】:
我想让 ListBoxItem 触发两个事件,我可以从包含 ListBox 的外部用户控件中捕获它们。这是我到目前为止得到的:
<ListBox
Background="Black"
Selected="listbox_selected"
x:Name="listBox">
<ListBox.Resources>
<Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsMouseOver,RelativeSource={RelativeSource Self}}"
Value="True">
<Setter Property="IsSelected" Value="True" />
</DataTrigger>
</Style.Triggers>
</Style>
</ListBox.Resources>
</ListBox>
现在,这将调用我的 listbox_Selected 事件。我想要的是在 IsMouseOver 时调用不同的事件或属性。为了清楚起见,我知道如何更改 ListBoxItem 本身的背景/前景或其他属性。但我想改变祖父母的一些东西。
【问题讨论】:
-
为什么不绑定到 IsSelected 属性从父到子?反之亦然。
标签: c# wpf user-controls listbox listboxitems