首页 > 解决方案 > 如何从选项卡控件中删除白色边框?

问题描述

我一直在寻找模板,但找不到任何东西。 例子

到目前为止我的 XAML:

 <TabControl HorizontalAlignment="Left" Height="285" BorderThickness="0" Margin="10,56,0,0" VerticalAlignment="Top" Width="495">
            <TabItem Header="Main" Foreground="#38acfc" BorderThickness="0" Background="#0c142c" FontFamily="Myriad Pro Cond" FontSize="14" Style="{DynamicResource CustomTabControl}">
                <Grid Background="#0c142c"/>
            </TabItem>
        </TabControl>

标签: wpfxaml

解决方案


使用此 ControlTemplate :

  <Style  TargetType="{x:Type TabControl}">
                <Setter Property="OverridesDefaultStyle" Value="True" />
                <Setter Property="SnapsToDevicePixels" Value="True" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type TabControl}">
                            <Grid KeyboardNavigation.TabNavigation="Local">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                                <TabPanel 
          Name="HeaderPanel"
          Grid.Row="0"
          Panel.ZIndex="1" 
          Margin="0,0,4,-1" 
          IsItemsHost="True"
          KeyboardNavigation.TabIndex="1"
          Background="Transparent" />
                                <Border 
          Name="Border" 
          Grid.Row="1" 
          Background="White" 
          BorderBrush="Transparent" 
          BorderThickness="1" 
          CornerRadius="2" 
          KeyboardNavigation.TabNavigation="Local"
          KeyboardNavigation.DirectionalNavigation="Contained"
          KeyboardNavigation.TabIndex="2" >
                                    <ContentPresenter 
            Name="PART_SelectedContentHost"
            Margin="0"
            ContentSource="SelectedContent" />
                                </Border>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsEnabled" Value="False">
                                    <Setter Property="Foreground" Value="Gray" />
                                    <Setter TargetName="Border" Property="BorderBrush" Value="Transparent" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

推荐阅读