如何使我的整个表在WPF中可单击

时间:2013-11-21 17:40:25

标签: wpf events tabcontrol

我有一个TabControl模板和样式,但我在选项卡中遇到了一些问题。

你会注意到我的标签(下面的边框)指定了宽度和高度,但不幸的是,整个边框不可点击,它只是里面的文字,所以如果我在标签中有一个字母,你有将鼠标指向字母上以选择标签。

如何点击边框内的任何位置选择标签?

这是我的ControlTemplate:

<Style x:Key="MainTabItem" TargetType="TabItem">
    <Setter Property="Foreground" Value="White" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="TabItem">
                <Border Name="Border" BorderThickness="1,1,1,0" BorderBrush="#EAF1F7" CornerRadius="3,3,0,0" Height="60" Width="70" Margin="-2,0,2,0">
                    <ContentPresenter x:Name="ContentSite" VerticalAlignment="Center" HorizontalAlignment="Center" ContentSource="Header"/>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="Foreground" Value="Black" />
                        <Setter TargetName="Border" Property="Background">
                            <Setter.Value>
                                <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                                    <GradientStop Color="#EDF1FA" Offset="0"/>
                                    <GradientStop Color="#EAF1F7" Offset="1"/>
                                </LinearGradientBrush>
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                    <Trigger Property="IsSelected" Value="False">
                        <Setter TargetName="Border" Property="BorderThickness" Value="0" />
                        <Setter TargetName="Border" Property="BorderThickness" Value="0" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
<Style x:Key="MainTabControl" TargetType="TabControl">

    <Setter Property="BorderThickness" Value="2"></Setter>
    <Setter Property="BorderBrush" Value="#CFE2F0"></Setter>
    <Setter Property="Background" Value="#EAF1F7"/>
    <Setter Property="BorderBrush" Value="#EAF1F7"/>
    <Setter Property="Effect">
        <Setter.Value>
            <DropShadowEffect Direction="150" BlurRadius="20" ShadowDepth="5" Opacity=".3"/>
        </Setter.Value>
    </Setter>
    <Setter Property="Background">
        <Setter.Value>
            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                <GradientStop Offset="0" Color="#EAF1F7" />
                <GradientStop Offset=".2" Color="#EAF1F7" />
                <GradientStop Offset=".6" Color="#C7D7E4" />
                <GradientStop Offset="1" Color="#EAF1F7" />
            </LinearGradientBrush>
        </Setter.Value>
    </Setter>
</Style>

1 个答案:

答案 0 :(得分:1)

向边框添加Background="Transparent"

原因是背景的默认值为null,而像素为&#39; null&#39;值未被命中测试可见。透明像素是可见的可见测试(这就是为什么&#39; null&#39;&#39; Transparent&#39;一起存在)的主要原因。