我将CheckBox添加到默认的TabControl模板中 TabControl有一个TabItem,它的内容是一个带有两个ColumDefinitions的Grid 我想在TabControl的CheckBox IsChecked时隐藏其中一列 以下是我想做/试图做的事情。
<TabControl>
<TabControl.Resources>
<Style TargetType="{x:Type TabControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabControl}">
<Grid x:Name="templateRoot">
<TabPanel x:Name="headerPanel"/>
<CheckBox x:Name="MyCheckbox"/>
<Border x:Name="contentPanel"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</TabControl.Resources>
<TabItem>
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="80">
<ColumnDefinition.Style>
<Style TargetType="ColumnDefinition">
<Setter Property="Width" Value="80"/>
<Style.Triggers>
<DataTrigger Binding="{Binding MyCheckbox.IsChecked, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type CheckBox}}}" Value="False">
<Setter Property="Width" Value="0"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ColumnDefinition.Style>
</ColumnDefinition>
</Grid.ColumnDefinitions>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</TabItem>
</TabControl>