在TabControl中使用ControlTemplate用于TabItems之后,TabItems选项卡的方向与TabStrippLacement不匹配

发布于 2025-02-09 06:08:37 字数 2230 浏览 2 评论 0原文

使用以下代码编辑TabControl中的TabItems和选定的TabItems的背景:

<TabControl.ItemContainerStyle>
            <Style TargetType="{x:Type TabItem}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TabItem}">
                        <Grid>
                            <Border 
                                            Name="Border"
                                            Margin="0,0,-4,0" 
                                            Background="Transparent"
                                            BorderBrush="Silver" 
                                            BorderThickness="1,1,1,1">
                                <ContentPresenter x:Name="ContentSite"
                                                VerticalAlignment="Center"
                                                HorizontalAlignment="Center"                                                    
                                                ContentSource="Header"
                                                Margin="12,2,12,2"
                                                RecognizesAccessKey="True"/>
                            </Border>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="Panel.ZIndex" Value="100" />
                                <Setter TargetName="Border" Property="Background" Value="Transparent" />
                                <Setter TargetName="Border" Property="BorderThickness" Value="1,1,1,0" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </TabControl.ItemContainerStyle>

它效果很好,除了我将Tabstripplacement设置为TabControl上的底部时,TabPanel将其停靠到底部时,TabItem仍然显示出来顶。它使得一些怪异的化妆品:

“底部tabs,好像在tabcontrol的顶部”

Using the following code to edit the background of TabItems and Selected TabItems in a TabControl:

<TabControl.ItemContainerStyle>
            <Style TargetType="{x:Type TabItem}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TabItem}">
                        <Grid>
                            <Border 
                                            Name="Border"
                                            Margin="0,0,-4,0" 
                                            Background="Transparent"
                                            BorderBrush="Silver" 
                                            BorderThickness="1,1,1,1">
                                <ContentPresenter x:Name="ContentSite"
                                                VerticalAlignment="Center"
                                                HorizontalAlignment="Center"                                                    
                                                ContentSource="Header"
                                                Margin="12,2,12,2"
                                                RecognizesAccessKey="True"/>
                            </Border>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="Panel.ZIndex" Value="100" />
                                <Setter TargetName="Border" Property="Background" Value="Transparent" />
                                <Setter TargetName="Border" Property="BorderThickness" Value="1,1,1,0" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </TabControl.ItemContainerStyle>

It work great except that when I set the TabStripPlacement to Bottom on the TabControl, while the TabPanel is docked to the bottom, the TabItems still display as if they were on top. It makes for some weird Cosmetics:

BottomTabs acting as if on Top of TabControl

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

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

发布评论

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

评论(1

手心的海 2025-02-16 06:08:37

在玩耍之后,我意识到问题是边缘和边界厚度,基础和选择时。而不是默认为-4,0的Amargin 0,0,而不是-4,0,0,0,而不是1,1,1,0边界厚度,则必须为1,0,1,1 。我当时认为这是一个需要发生的转变,但是调整利润率可以解决问题。

新代码:

<TabControl.ItemContainerStyle>
        <Style TargetType="{x:Type TabItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TabItem}">
                    <Grid>
                        <Border 
                                        Name="Border"
                                        **Margin="-4,0,0,0"** 
                                        Background="Transparent"
                                        BorderBrush="Silver" 
                                        BorderThickness="1,1,1,1">
                            <ContentPresenter x:Name="ContentSite"
                                            VerticalAlignment="Center"
                                            HorizontalAlignment="Center"                                                    
                                            ContentSource="Header"
                                            Margin="12,2,12,2"
                                            RecognizesAccessKey="True"/>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="Panel.ZIndex" Value="100" />
                            <Setter TargetName="Border" Property="Background" Value="Transparent" />
                            <Setter TargetName="Border" Property="BorderThickness" **Value="1,0,1,1"** />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</TabControl.ItemContainerStyle>

After playing around with it, I realized the issue was with the margin and border thickness, base and when selected. Instead of amargin 0,0,-4,0 at default, needs to be -4,0,0,0 and instead of 1,1,1,0 border thickness when selected it needs to be 1,0,1,1. I was thinking it was a transform that needed to happen, but adjusting the margins did the trick.

new code:

<TabControl.ItemContainerStyle>
        <Style TargetType="{x:Type TabItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TabItem}">
                    <Grid>
                        <Border 
                                        Name="Border"
                                        **Margin="-4,0,0,0"** 
                                        Background="Transparent"
                                        BorderBrush="Silver" 
                                        BorderThickness="1,1,1,1">
                            <ContentPresenter x:Name="ContentSite"
                                            VerticalAlignment="Center"
                                            HorizontalAlignment="Center"                                                    
                                            ContentSource="Header"
                                            Margin="12,2,12,2"
                                            RecognizesAccessKey="True"/>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="Panel.ZIndex" Value="100" />
                            <Setter TargetName="Border" Property="Background" Value="Transparent" />
                            <Setter TargetName="Border" Property="BorderThickness" **Value="1,0,1,1"** />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</TabControl.ItemContainerStyle>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文