【发布时间】:2012-01-03 08:32:54
【问题描述】:
我正在构建一个工具来同时编辑多个数据库对象,我很想知道你们对突出显示方案的想法。
在我的ViewModel 中,我有一个Jurisdictions 的集合Juris,它们与用户选择要编辑的任何项目相关联。我还有一个由所有选定项目共享的管辖权子集,“CommonJuris”。我的问题是:有没有一种简单的方法可以用完整的集合填充ListBox,并突出显示子集合中的项目?
目前我的Jurisdiction Model 中有一个布尔属性IsCommon。我真的不希望在Model 中出现这种情况,但我还没有找到更好的解决方案。 Jurisdiction 没有 ViewModel,因为这是其中唯一的东西。
这是我的 ListBox 本身的 XAML:
<ListBox Grid.Row="1" Grid.Column="2" ItemContainerStyle="{StaticResource JuriAndTT}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
HorizontalContentAlignment="Stretch"
ItemsSource="{Binding Juris}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
风格:
<Style TargetType="{x:Type ListBoxItem}" x:Key="JuriAndTT">
<Style.Triggers>
<DataTrigger Binding="{Binding IsCommon}" Value="True">
<Setter Property="Background" Value="PowderBlue"/>
<Setter Property="Foreground" Value="Black"/>
</DataTrigger>
</Style.Triggers>
</Style>
【问题讨论】:
标签: c# wpf xaml listbox highlighting