0
我正在構建一個工具來同時編輯多個數據庫對象,並且很想讓您對高亮方案有所瞭解。
在我的ViewModel
中,我有一個Juris
,Jurisdictions
的集合,這些集合與用戶選擇編輯的任何項目相關聯。我還有一個由所有選定項目「CommonJuris」共享的轄區子集。我的問題是:是否有一種簡單的方法可以用完整集合填充ListBox
,並突出顯示子集合中的項目?
目前我有一個布爾屬性,IsCommon
,在我的Jurisdiction Model
。我真的不想在Model
這個,但我還沒有找到更好的解決方案。 Jurisdiction
沒有ViewModel
,因爲這是唯一的東西。WPF子組突出顯示
這裏是我的列表框本身的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>