【发布时间】:2015-04-21 04:25:30
【问题描述】:
我的 tabitems 有以下风格:
<Style x:Key="BoutonMenuHaut" TargetType="{x:Type TabItem}">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Border Height="40" HorizontalAlignment="Stretch" CornerRadius="0" Name="border">
<Grid>
<ContentPresenterVerticalAlignment="Center"
HorizontalAlignment="Left"
TextBlock.Foreground="{StaticResource CouleurTexteBoutonsHaut}"
TextBlock.FontSize="{DynamicResource FontSizeBig}"
Name="textTab"
ContentSource="Header" Margin="10,0,60,0"
RecognizesAccessKey="True">
</ContentPresenter>
<Rectangle Height="2" x:Name="separation" Fill="Red" VerticalAlignment="Bottom" />
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
如您所见,我将字体大小绑定到这样定义的值:
xmlns:sys="clr-namespace:System;assembly=mscorlib"
<sys:Double x:Key="FontSizeBig">16</sys:Double>
在 window_sizechanged 事件中我这样做:
this.Resources["FontSizeBig"] = TextSizeFromResolution(12, height);
height 是屏幕的高度。
但是当我调整窗口大小时,我的 tabitem 不会自行调整大小,并且我无法再看到页面中的所有标签。
所以我的问题是:当大小发生变化时,如何强制 tabcontrol 调整 tabitems 的大小? (因为文本的大小已经改变,所以 tabitem 的宽度也应该改变。 我已经尝试过 InvalidateMeasure,更新布局...但我无法让它工作。
你能帮帮我吗?
谢谢!
【问题讨论】: