我对WPF的相关知识不太了解,但是我尝试着自己重新设计一个TabItem。
如您所见,选项卡填满了整个窗口的宽度。与我的原始目的不同,我实际上想要让选项卡的宽度基于其内部文本。就像原始样式一样,只是重新设计过。
我的代码中的样式:
<Style x:Key="ZoidTab" TargetType="{x:Type TabItem}" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate x:Name="ZoidTemplate" TargetType="{x:Type TabItem}">
<Border Width="Auto" Height="Auto">
<Grid x:Name="grid">
<Polygon
Fill="Turquoise"
Points="0,1 0.05,0 0.95,0 1,1"
Stretch="Fill"
Margin="0,0,0,0"
/>
<ContentPresenter x:Name="tabContent" HorizontalAlignment="Center" ContentSource="Header" VerticalAlignment="Center" TextElement.Foreground="#FFFFFFFF"/>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="FontSize" Value="12pt"/>
</Style>
我想知道我必须修复什么才能使宽度正确...谢谢。