我希望ComboBox中的选定项目看起来与下拉列表中的实例不同。
<ComboBox ItemsSource="{Binding ViewList}" SelectedItem="{Binding SelectedView}">
<ComboBox.Resources>
<DataTemplate DataType="{x:Type vm:View}">
<StackPanel Orientation="Horizontal">
<c:Icon x:Name="Icon" IconShape="{DynamicResource z.Users}" Margin="5,0" Background="{Binding Foreground, RelativeSource={RelativeSource Self}}"/>
<StackPanel>
<StackPanel>
<TextBlock x:Name="CurrentView" Text="Current View"
Foreground="{DynamicResource Pallete.Primary.Brighter}"
Visibility="{Binding IsSelected, Converter={StaticResource bool2VisibilityConverter}}"/>
<TextBlock x:Name="Title" Text="{Binding Title}"/>
</StackPanel>
</StackPanel>
</StackPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Type}" Value="SeparatorView">
<Setter TargetName="Icon" Property="Visibility" Value="Collapsed"/>
<Setter TargetName="Title" Property="FontWeight" Value="Bold"/>
</DataTrigger>
<DataTrigger Binding="{Binding Type}" Value="YearView">
<Setter TargetName="Icon" Property="IconShape" Value="{DynamicResource z.Bookmark}"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ComboBox.Resources>
</ComboBox>
我可以在CurrentView
的可见性属性或触发器中使用一些东西吗?
下面是一个示例,您可以使用DataTrigger
在ComboBox
中选择TextBlock
时修改的Foreground
:
<ComboBox ItemsSource="{Binding ListOfStrings}">
<ComboBox.Resources>
<DataTemplate DataType="{x:Type sys:String}">
<TextBlock x:Name="txt" Text="{Binding}" Foreground="Red" />
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ComboBoxItem}}" Value="{x:Null}">
<Setter TargetName="txt" Property="Foreground" Value="Green"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ComboBox.Resources>
</ComboBox>
我相信以下是您正在寻找的:
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ComboBoxItem}}" Value="{x:Null}">