WPF TabControl XP 样式问题

发布于 2024-08-05 23:47:04 字数 3961 浏览 4 评论 0原文

我正在运行 Windows 7 的 PC 上设计 TabControl 的样式,一切看起来都很好,但是当我尝试在 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>

任何帮助将不胜感激!

I'm working on styling a TabControl on a PC runnnig Windows 7 and everything looked fine, but when I tried running it in Windows XP, I get a hideous white border around the TabControl:

alt text

I believe it's the same problem fighting with luna (described here TabControl without border wpf (XP)), but I'm at a loss as to what to change in the template...

The style for the TabControl is as follows:

<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>

and the actual TabControl' XAML (nothing fancy) is:

<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>

any help would be much appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

舞袖。长 2024-08-12 23:47:04

找到了一个解决方案,正常方法 - 将一个简单样式的控件分开:)

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

<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>

Found a solution, normal method - pull a simple styled control in blend apart :)

Here's the style I had to add to remove that border in case anyone is interested:

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文