I'm trying to change a selected TabItem's width in the following way:
<Style TargetType="{x:Type TabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Grid x:Name="Root">
<Border x:Name="Border" Background="{TemplateBinding Background}">
<ContentPresenter x:Name="ContentSite" VerticalAlignment="Center" HorizontalAlignment="Stretch" ContentSource="Header" Margin="12,2,12,2"/>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Width"
From="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem}, Mode=FindAncestor}, Path=ActualWidth}"
To="200"
Duration="0:0:1"/>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
</Style.Triggers>
</Style>
TabItem の「Width」プロパティを明示的に指定していないため、アニメーションの「From」プロパティを指定する必要があります。これは、カスタム レイアウト コンテナーによって計算されます。しかし、アニメーションの「From」プロパティを TabItem の「ActualWidth」プロパティにバインドしようとすると、「System.Windows.Controls.TabItem」の初期化で例外がスローされました。「トリガー」セクションを「ControlTemplate」セクション内に移動しようとしましたが、効果がありませんでした。だから私は2つの質問があります:
1)「From」プロパティを、私が行った方法で TabItem の ActualWidth にバインドできないのはなぜですか?
2) どうすれば望ましい動作を実現できますか?
ヒントをいただければ幸いです。