在 ItemsContainerStyle for 中TabControl
,创建一个绑定到属性(例如)的 DataTriggerIsDiscontinued
并从那里设置 Opacity
<TabControl ItemsSource="{Binding Products}" Name="ProductsTabControl">
<TabControl.ItemContainerStyle>
<Style TargetType="TabItem">
<Style.Triggers>
<DataTrigger Binding="{Binding IsDiscontinued}" Value="True">
<Setter Property="Opacity" Value="0.2"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TabControl.ItemContainerStyle>
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</TabControl.ItemTemplate>
</TabControl>
更新
如果您想让已停产选项卡的内容半透明,您可以做同样的事情,但在DataTemplate
<TabControl ItemsSource="{Binding Products}" Name="ProductsTabControl">
<TabControl.Resources>
<DataTemplate DataType="{x:Type local:Product}">
<Border Name="bg" BorderBrush="Black" BorderThickness="1">
<TextBlock Text="{Binding Name}"/>
</Border>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsDiscontinued}" Value="True">
<Setter TargetName="bg" Property="Opacity" Value="0.2"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</TabControl.Resources>
<!--...-->
</TabControl>