我在 ItemTemplate 中有一个带有扩展器的列表框。我设法将扩展器的 IsExpanded 属性绑定到 ListBoxItem 的 IsSelected 属性确定。现在我想将样式应用于 ListBoxItem 的内容,该内容也绑定到 IsSelected 属性。
<ListBox.ItemTemplate>
<DataTemplate>
<Border Name="myBorder">
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Description}" />
<StackPanel Orientation="Horizontal">
<TextBlock Text="Date:"/>
<TextBlock Text="{Binding Date}"/>
</StackPanel>
<dx:DXExpander Name="expanderDetails"
IsExpanded="{Binding Mode=TwoWay, Path=IsSelected,
RelativeSource={RelativeSource AncestorType=ListBoxItem, Mode=FindAncestor}}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Count:"/>
<TextBlock Text="{Binding Count}"/>
</StackPanel>
</dx:DXExpander>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
我想要做的是以某种方式将“myBorder”边框的样式设置为“NotSelectedBorderStyle”以用于未选择的ListBoxItems,并将“SelectedBorderStyle”用于SelectedItem(具有单选的ListBox)。
仅供参考,样式定义了背景,边框和那种东西,只是为了明确选择了哪个项目,这些样式没有什么花哨的。
我在这里尝试了接受的答案,但如果我完全切换样式,我会失去我的 DXExpander 拥有的漂亮的扩展动画。
我想一定有一些使用触发器的解决方案,但我不能只打对了位置。