none
TabControl 的一个边框的问题 RRS feed

  • 问题

  • <TabControl Background="Black" BorderThickness="0" Padding="0" Height="200"  Name="tabControl1"  Width="200"  
                <TabItem Header="tabItem1" Name="tabItem1">
                    <Grid >
                    	<ListBox Background="Black" Foreground="#FFF5E9E9"  >
                    		<ListBoxItem>123</ListBoxItem>
    				<ListBoxItem>123</ListBoxItem>
    				<ListBoxItem>123</ListBoxItem>
                    	</ListBox>
    		</Grid>
                </TabItem>
    </TabControl>

    这样设置了 ,请问那个边框,是哪控件的,怎么去掉他,或者换个颜色

    是默认模版里面ContentPresenter的产生的么 其他好像都不是。

    2012年4月20日 5:42

答案

  • 以下是默认TabControl的Style,请参考。

    <SolidColorBrush x:Key="TabControlNormalBorderBrush"
                         Color="#8C8E94"/>
        <Style x:Key="{x:Type TabControl}"
               TargetType="{x:Type TabControl}">
            <Setter Property="Foreground"
                    Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="Padding"
                    Value="4,4,4,4"/>
            <Setter Property="BorderThickness"
                    Value="1"/>
            <Setter Property="BorderBrush"
                    Value="{StaticResource TabControlNormalBorderBrush}"/>
            <Setter Property="Background"
                    Value="#F9F9F9"/>
            <Setter Property="HorizontalContentAlignment"
                    Value="Center"/>
            <Setter Property="VerticalContentAlignment"
                    Value="Center"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TabControl}">
                        <Grid KeyboardNavigation.TabNavigation="Local"
                              SnapsToDevicePixels="true"
                              ClipToBounds="true">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition x:Name="ColumnDefinition0"/>
                                <ColumnDefinition x:Name="ColumnDefinition1"
                                                  Width="0"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition x:Name="RowDefinition0"
                                               Height="Auto"/>
                                <RowDefinition x:Name="RowDefinition1"
                                               Height="*"/>
                            </Grid.RowDefinitions>
                            <TabPanel x:Name="HeaderPanel"
                                      Panel.ZIndex ="1" 
                                      KeyboardNavigation.TabIndex="1"
                                      Grid.Column="0"
                                      Grid.Row="0"
                                      Margin="2,2,2,0"
                                      IsItemsHost="true"/>
                            <Border x:Name="ContentPanel"
                                    Background="{TemplateBinding Background}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    KeyboardNavigation.TabNavigation="Local"
                                    KeyboardNavigation.DirectionalNavigation="Contained"
                                    KeyboardNavigation.TabIndex="2"
                                    Grid.Column="0"
                                    Grid.Row="1">
                                <ContentPresenter x:Name="PART_SelectedContentHost"
                                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                                  Margin="{TemplateBinding Padding}"
                                                  ContentSource="SelectedContent"/>
                            </Border>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="TabStripPlacement"
                                     Value="Bottom">
                                <Setter Property="Grid.Row"
                                        Value="1"
                                        TargetName="HeaderPanel"/>
                                <Setter Property="Grid.Row"
                                        Value="0"
                                        TargetName="ContentPanel"/>
                                <Setter Property="Height"
                                        Value="*"
                                        TargetName="RowDefinition0"/>
                                <Setter Property="Height"
                                        Value="Auto"
                                        TargetName="RowDefinition1"/>
                                <Setter Property="Margin"
                                        Value="2,0,2,2"
                                        TargetName="HeaderPanel"/>
                            </Trigger>
                            <Trigger Property="TabStripPlacement"
                                     Value="Left">
                                <Setter Property="Grid.Row"
                                        Value="0"
                                        TargetName="HeaderPanel"/>
                                <Setter Property="Grid.Row"
                                        Value="0"
                                        TargetName="ContentPanel"/>
                                <Setter Property="Grid.Column"
                                        Value="0"
                                        TargetName="HeaderPanel"/>
                                <Setter Property="Grid.Column"
                                        Value="1"
                                        TargetName="ContentPanel"/>
                                <Setter Property="Width"
                                        Value="Auto"
                                        TargetName="ColumnDefinition0"/>
                                <Setter Property="Width"
                                        Value="*"
                                        TargetName="ColumnDefinition1"/>
                                <Setter Property="Height"
                                        Value="*"
                                        TargetName="RowDefinition0"/>
                                <Setter Property="Height"
                                        Value="0"
                                        TargetName="RowDefinition1"/>
                                <Setter Property="Margin"
                                        Value="2,2,0,2"
                                        TargetName="HeaderPanel"/>
                            </Trigger>
                            <Trigger Property="TabStripPlacement"
                                     Value="Right">
                                <Setter Property="Grid.Row"
                                        Value="0"
                                        TargetName="HeaderPanel"/>
                                <Setter Property="Grid.Row"
                                        Value="0"
                                        TargetName="ContentPanel"/>
                                <Setter Property="Grid.Column"
                                        Value="1"
                                        TargetName="HeaderPanel"/>
                                <Setter Property="Grid.Column"
                                        Value="0"
                                        TargetName="ContentPanel"/>
                                <Setter Property="Width"
                                        Value="*"
                                        TargetName="ColumnDefinition0"/>
                                <Setter Property="Width"
                                        Value="Auto"
                                        TargetName="ColumnDefinition1"/>
                                <Setter Property="Height"
                                        Value="*"
                                        TargetName="RowDefinition0"/>
                                <Setter Property="Height"
                                        Value="0"
                                        TargetName="RowDefinition1"/>
                                <Setter Property="Margin"
                                        Value="0,2,2,2"
                                        TargetName="HeaderPanel"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" 
                                     Value="false">
                                <Setter Property="Foreground" 
                                        Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    • 已标记为答案 小携 2012年4月20日 7:04
    2012年4月20日 6:05
  • 好吧...发现了...原来是ListBox的边框...汗死...

    还是要谢谢马里的回答...
    • 已编辑 小携 2012年4月20日 7:04
    • 已标记为答案 小携 2012年4月20日 7:04
    2012年4月20日 7:03

全部回复

  • 以下是默认TabControl的Style,请参考。

    <SolidColorBrush x:Key="TabControlNormalBorderBrush"
                         Color="#8C8E94"/>
        <Style x:Key="{x:Type TabControl}"
               TargetType="{x:Type TabControl}">
            <Setter Property="Foreground"
                    Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="Padding"
                    Value="4,4,4,4"/>
            <Setter Property="BorderThickness"
                    Value="1"/>
            <Setter Property="BorderBrush"
                    Value="{StaticResource TabControlNormalBorderBrush}"/>
            <Setter Property="Background"
                    Value="#F9F9F9"/>
            <Setter Property="HorizontalContentAlignment"
                    Value="Center"/>
            <Setter Property="VerticalContentAlignment"
                    Value="Center"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TabControl}">
                        <Grid KeyboardNavigation.TabNavigation="Local"
                              SnapsToDevicePixels="true"
                              ClipToBounds="true">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition x:Name="ColumnDefinition0"/>
                                <ColumnDefinition x:Name="ColumnDefinition1"
                                                  Width="0"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition x:Name="RowDefinition0"
                                               Height="Auto"/>
                                <RowDefinition x:Name="RowDefinition1"
                                               Height="*"/>
                            </Grid.RowDefinitions>
                            <TabPanel x:Name="HeaderPanel"
                                      Panel.ZIndex ="1" 
                                      KeyboardNavigation.TabIndex="1"
                                      Grid.Column="0"
                                      Grid.Row="0"
                                      Margin="2,2,2,0"
                                      IsItemsHost="true"/>
                            <Border x:Name="ContentPanel"
                                    Background="{TemplateBinding Background}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    KeyboardNavigation.TabNavigation="Local"
                                    KeyboardNavigation.DirectionalNavigation="Contained"
                                    KeyboardNavigation.TabIndex="2"
                                    Grid.Column="0"
                                    Grid.Row="1">
                                <ContentPresenter x:Name="PART_SelectedContentHost"
                                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                                  Margin="{TemplateBinding Padding}"
                                                  ContentSource="SelectedContent"/>
                            </Border>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="TabStripPlacement"
                                     Value="Bottom">
                                <Setter Property="Grid.Row"
                                        Value="1"
                                        TargetName="HeaderPanel"/>
                                <Setter Property="Grid.Row"
                                        Value="0"
                                        TargetName="ContentPanel"/>
                                <Setter Property="Height"
                                        Value="*"
                                        TargetName="RowDefinition0"/>
                                <Setter Property="Height"
                                        Value="Auto"
                                        TargetName="RowDefinition1"/>
                                <Setter Property="Margin"
                                        Value="2,0,2,2"
                                        TargetName="HeaderPanel"/>
                            </Trigger>
                            <Trigger Property="TabStripPlacement"
                                     Value="Left">
                                <Setter Property="Grid.Row"
                                        Value="0"
                                        TargetName="HeaderPanel"/>
                                <Setter Property="Grid.Row"
                                        Value="0"
                                        TargetName="ContentPanel"/>
                                <Setter Property="Grid.Column"
                                        Value="0"
                                        TargetName="HeaderPanel"/>
                                <Setter Property="Grid.Column"
                                        Value="1"
                                        TargetName="ContentPanel"/>
                                <Setter Property="Width"
                                        Value="Auto"
                                        TargetName="ColumnDefinition0"/>
                                <Setter Property="Width"
                                        Value="*"
                                        TargetName="ColumnDefinition1"/>
                                <Setter Property="Height"
                                        Value="*"
                                        TargetName="RowDefinition0"/>
                                <Setter Property="Height"
                                        Value="0"
                                        TargetName="RowDefinition1"/>
                                <Setter Property="Margin"
                                        Value="2,2,0,2"
                                        TargetName="HeaderPanel"/>
                            </Trigger>
                            <Trigger Property="TabStripPlacement"
                                     Value="Right">
                                <Setter Property="Grid.Row"
                                        Value="0"
                                        TargetName="HeaderPanel"/>
                                <Setter Property="Grid.Row"
                                        Value="0"
                                        TargetName="ContentPanel"/>
                                <Setter Property="Grid.Column"
                                        Value="1"
                                        TargetName="HeaderPanel"/>
                                <Setter Property="Grid.Column"
                                        Value="0"
                                        TargetName="ContentPanel"/>
                                <Setter Property="Width"
                                        Value="*"
                                        TargetName="ColumnDefinition0"/>
                                <Setter Property="Width"
                                        Value="Auto"
                                        TargetName="ColumnDefinition1"/>
                                <Setter Property="Height"
                                        Value="*"
                                        TargetName="RowDefinition0"/>
                                <Setter Property="Height"
                                        Value="0"
                                        TargetName="RowDefinition1"/>
                                <Setter Property="Margin"
                                        Value="0,2,2,2"
                                        TargetName="HeaderPanel"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" 
                                     Value="false">
                                <Setter Property="Foreground" 
                                        Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    • 已标记为答案 小携 2012年4月20日 7:04
    2012年4月20日 6:05
  • 好吧...发现了...原来是ListBox的边框...汗死...

    还是要谢谢马里的回答...
    • 已编辑 小携 2012年4月20日 7:04
    • 已标记为答案 小携 2012年4月20日 7:04
    2012年4月20日 7:03