在TabControl中使用ControlTemplate用于TabItems之后,TabItems选项卡的方向与TabStrippLacement不匹配
使用以下代码编辑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仍然显示出来顶。它使得一些怪异的化妆品:
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:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在玩耍之后,我意识到问题是边缘和边界厚度,基础和选择时。而不是默认为-4,0的Amargin 0,0,而不是-4,0,0,0,而不是1,1,1,0边界厚度,则必须为1,0,1,1 。我当时认为这是一个需要发生的转变,但是调整利润率可以解决问题。
新代码:
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: