我有两个列表。物品清单和水果清单。如果事物列表中的项目是水果列表中的水果,我希望突出显示该项目。
我喜欢用数据绑定,通过xmal,而不是代码隐藏b/c,我正在做MVVM模式。我已经尝试了DataTrigger和转换器,但不能得到它的工作。请帮帮忙。
谢谢。
<ListBox ItemsSource="{Binding Things}"
Name="ListOfThigns"
Grid.Row="1">
<DataTemplate>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Fruits}" >
<Setter Property="ListBoxItem.Background" Value="Green"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ListBox>
<ListBox ItemsSource="{Binding Fruits}"
Name="ListOfFruits"
Grid.Column="1"
Grid.Row="1">
</ListBox>发布于 2015-12-08 03:12:33
或者,如果Fruit继承自Thing (水果是一件东西):
<ListView ItemsSource="{Binding Things}">
<ListView.Resources>
<DataTemplate DataType="{x:Type dm:Fruit}">
<TextBlock Text="{Binding Name}" Background="RoyalBlue"/>
</DataTemplate>
<DataTemplate DataType="{x:Type dm:Thing}">
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</ListView.Resources>
</ListView>https://stackoverflow.com/questions/34140606
复制相似问题