c#wpf TabItem选择未完全工作
本文关键字:工作 TabItem 选择 c#wpf | 更新日期: 2023-09-27 18:24:28
我有TabItem:的自定义标题样式
<Style TargetType="{x:Type TabItem}" x:Key="purpleTab">
<Setter Property="Background" Value="#E5E5E5"/>
<Setter Property="Width" Value="97"/>
<Setter Property="Height" Value="70"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Margin" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TabItem">
<Border Name="Border" BorderThickness="0,0,0,2" BorderBrush="#E5E5E5">
<ContentPresenter x:Name="ContentSite"
VerticalAlignment="Center"
HorizontalAlignment="Center"
ContentSource="Header" Width="97" Height="66"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Border" Property="BorderBrush" Value="#1F1F1F" />
</Trigger>
<Trigger Property="IsSelected" Value="False">
<Setter TargetName="Border" Property="BorderBrush" Value="#E5E5E5" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我的TabItem看起来是这样的:
<TabItem x:Name="AccTabItem"
Style="{DynamicResource purpleTab}">
<TabItem.Header>
<StackPanel Orientation="Vertical">
<Image Height="30" Width="30" Margin="0 10 0 0"
Source="{Binding IsSelected, ElementName=AccTabItem,
Converter={StaticResource IsSelectedToIconSourceConverter},
ConverterParameter=ac}"/>
<TextBlock Text="{DynamicResource Account}" FontSize="12" Margin="0 6 0 0"
Foreground="{Binding IsSelected, ElementName=AccTabItem,
Converter={StaticResource IsSelectedToForegroundColor}}" HorizontalAlignment="Center"/>
</StackPanel>
</TabItem.Header>
<view:UserSettingsView/>
</TabItem>
我的问题是,当我点击图像或文本(在选项卡标题中)时,它会很好地选择选项卡,但不会在选项卡标题区域的其余部分进行选择。如何设置选择以处理图像和文本元素(处理整个标题区域)?
例如,在样式:中向Border
添加透明的Background
<Border Name="Border" BorderThickness="0,0,0,2" BorderBrush="#E5E5E5" Background="Transparent">
默认情况下,背景设置为{x:Null}