WPF TabControl XP样式问题

时间:2009-10-02 07:58:57

标签: wpf windows-xp styles tabcontrol

我正在研究在PC上运行一个TabControl在Windows 7上运行并且一切看起来都不错,但是当我尝试在Windows XP中运行时,我在TabControl周围出现了一个可怕的白色边框:

alt text

我认为与luna战斗的问题相同(这里描述TabControl without border wpf (XP)),但我对模板中的变化感到茫然......

TabControl的样式如下:

<Style TargetType="{x:Type TabItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TabItem}">
                    <Grid>
                        <Border Name="Border" Margin="0,10,0,-10" BorderBrush="Transparent" BorderThickness="1,1,0,0" CornerRadius="5,0,0,5">
                            <Border.Background>
                                <LinearGradientBrush EndPoint="1.407,0.5" StartPoint="-0.407,0.5">
                                    <GradientStop Color="#49000000" Offset="0"/>
                                    <GradientStop Offset="1" Color="#09FFFFFF"/>
                                </LinearGradientBrush>
                            </Border.Background>
                            <ContentPresenter x:Name="ContentSite" 
                                              TextBlock.FontSize="15"
                                              TextBlock.Foreground="#22ffffff"
                                              VerticalAlignment="Center" 
                                              HorizontalAlignment="Center" 
                                              ContentSource="Header" 
                                              Margin="5,5,2,5" 
                                              RecognizesAccessKey="True">
                                <ContentPresenter.LayoutTransform>
                                    <RotateTransform Angle="270" />
                                </ContentPresenter.LayoutTransform>
                            </ContentPresenter>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="Panel.ZIndex" Value="100" />
                            <Setter TargetName="Border" Property="Background" Value="Red" />
                            <Setter TargetName="Border" Property="BorderThickness" Value="1,1,0,0" />
                            <Setter TargetName="ContentSite" Property="TextBlock.Foreground" Value="White"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="Border" Property="Background" Value="DarkRed" />
                            <Setter TargetName="Border" Property="BorderBrush" Value="Black" />
                            <Setter Property="Foreground" Value="DarkGray" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

和实际的TabControl'XAML(没什么特别的)是:

<TabControl Grid.Row="1" Grid.Column="0" Margin="5,5" TabStripPlacement="Left" 
                Background="Transparent" HorizontalAlignment="Stretch" BorderThickness="0,0,0,0">
        <TabControl.BitmapEffect>
            <DropShadowBitmapEffect Color="Black" Direction="270"/>
        </TabControl.BitmapEffect>

        <TabItem Header="Tab Item 1"/>
        <TabItem Header="Tab Item 2"/>
        <TabItem Header="Tab Item 3"/>
        <TabItem Header="Tab Item 4"/>
    </TabControl>

任何帮助都会非常感激!

1 个答案:

答案 0 :(得分:2)

找到一个解决方案,正常的方法 - 将一个简单的样式控件拉出来混合:)

这是我必须添加的样式,以便在有人感兴趣时删除该边框:

<Style TargetType="{x:Type TabControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TabControl}">
                    <Grid KeyboardNavigation.TabNavigation="Local">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="33"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <TabPanel Grid.Column="0" Margin="0,0,4,-1" x:Name="HeaderPanel" Background="Transparent" IsItemsHost="True" Panel.ZIndex="1" KeyboardNavigation.TabIndex="1"/>
                        <Border Grid.Column="1" x:Name="Border" Background="{DynamicResource WindowBackgroundBrush}" BorderBrush="{DynamicResource SolidBorderBrush}" BorderThickness="0" CornerRadius="2" KeyboardNavigation.DirectionalNavigation="Contained" KeyboardNavigation.TabNavigation="Local" KeyboardNavigation.TabIndex="2">
                            <ContentPresenter Margin="4" x:Name="PART_SelectedContentHost" ContentSource="SelectedContent"/>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Foreground" Value="{DynamicResource DisabledForegroundBrush}"/>
                            <Setter Property="BorderBrush" Value="{DynamicResource DisabledBorderBrush}" TargetName="Border"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>