我是 wpf 的新手,我想在 ButtonClick 上更改我的 TapStripPlacement。我尝试自己找到解决方案,但无法做到。我会对快速解决方案感到非常高兴。
这是我的代码:
<Window x:Class="Pages.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="TabControl" Height="350" Width="525">
<Window.Resources>
<SolidColorBrush x:Key="Foreground" Color="#FF9531b1"></SolidColorBrush>
<SolidColorBrush x:Key="Background" Color="Transparent"></SolidColorBrush>
<ControlTemplate x:Key="TabItemControlTemplate" TargetType="{x:Type TabItem}">
<Grid SnapsToDevicePixels="True">
<Border x:Name="Bd" BorderBrush="{StaticResource Foreground}" BorderThickness="0" Padding="{TemplateBinding Padding}">
<Border.Style>
<Style TargetType="{x:Type Border}">
<Setter Property="Background" Value="{StaticResource Background}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsSelected}" Value="True">
<Setter Property="Background" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}" />
</DataTrigger>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsMouseOver}" Value="True">
<Setter Property="Background" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}" />
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
<ContentPresenter x:Name="Content" ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentSource="Header" HorizontalAlignment="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type ItemsControl}}}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{Binding VerticalContentAlignment, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type ItemsControl}}}"/>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Bd" Property="Background" Value="{StaticResource Foreground}"></Setter>
<Setter TargetName="Content" Property="TextBlock.Foreground" Value="White"></Setter>
<Setter TargetName="Content" Property="TextBlock.FontWeight" Value="Heavy"></Setter>
</Trigger>
<MultiTrigger >
<MultiTrigger.Conditions >
<Condition Property="IsSelected" Value="True"></Condition>
<Condition Property="IsMouseOver" Value="false"></Condition>
</MultiTrigger.Conditions>
<Setter TargetName="Content" Property="TextBlock.Foreground" Value="{StaticResource Foreground}"></Setter>
<Setter TargetName="Content" Property="TextBlock.FontWeight" Value="Heavy"></Setter>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="1">
<Button x:Name="btnTop">Top</Button>
<Button Name="btnRight">Right</Button>
<Button Name="btnBottom">Bottom</Button>
<Button Name="btnLeft">Left</Button>
</StackPanel>
<TabControl Grid.Column="0" x:Name="MyControl" Height="200"
Background="Transparent"
BorderThickness="0,1,0,0"
BorderBrush="{StaticResource Foreground}" TabStripPlacement="Top">
<TabItem Header="tab1" Background="Transparent" Template="{DynamicResource TabItemControlTemplate}"/>
<TabItem Header="tab2" Background="Transparent" Template="{DynamicResource TabItemControlTemplate}"/>
<TabItem Header="tab3" Background="Transparent" Template="{DynamicResource TabItemControlTemplate}"/>
</TabControl>
</Grid>
提前致谢