Adorner として FlowDocumentReader をポップアップするためにクリックする ToggleButton があります。この FlowDocument は、要素を表示/非表示にする DataTrigger を持つ ControlTemplate の一部です。
次のトリガーを使用すると、すべて正常に動作します。私は DataTrigger といくつかの Setter を使用しています。私の要素は、ToggleButton をチェックしたときに指定した Height と Width で正しく表示されます。
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding ElementName=adorner, Path=AdornedElement.IsChecked}" Value="True" >
<Setter TargetName="mainBorder" Property="Height" Value="437"></Setter>
<Setter TargetName="mainBorder" Property="Width" Value="537"></Setter>
</DataTrigger>
</ControlTemplate.Triggers>
要素が表示されるときに発生するアニメーションが必要なため、ストーリーボードを使用しようとしました。これは機能しません。何も起こらないようです:
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding ElementName=adorner, Path=AdornedElement.IsChecked}" Value="True" >
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard Storyboard.TargetName="mainBorder">
<DoubleAnimation Duration="0:0:0.2" Storyboard.TargetProperty="Width" To="537" />
<DoubleAnimationUsingKeyFrames BeginTime="0:0:0.2" Duration="0:0:0.3" Storyboard.TargetProperty="Height">
<LinearDoubleKeyFrame Value="417" KeyTime="0:0:0.2" />
<LinearDoubleKeyFrame Value="437" KeyTime="0:0:0.24" />
<LinearDoubleKeyFrame Value="417" KeyTime="0:0:0.3" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard Storyboard.TargetName="mainBorder">
<DoubleAnimationUsingKeyFrames Duration="0:0:0.2" Storyboard.TargetProperty="Width">
<LinearDoubleKeyFrame Value="0" KeyTime="0:0:0.2" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="0:0:0.2" Duration="0:0:0.2" Storyboard.TargetProperty="Height">
<LinearDoubleKeyFrame Value="0" KeyTime="0:0:0.2" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>
</ControlTemplate.Triggers>
Storyboard コンテキストは Setter とは完全に異なりますか? ある場所では機能するのに、他の場所では機能しないのはなぜですか?
奇妙なことに、この変更を行うと、バインド エラーが出力ウィンドウに表示されます。DataTrigger の実際のバインディングには触れていません。内容だけです。
System.Windows.Data エラー: 4: 参照 'ElementName=adorner' を使用したバインディングのソースが見つかりません。BindingExpression:Path=AdornedElement.IsChecked; DataItem=null; ターゲット要素は 'Control' (Name='') です。ターゲット プロパティは 'NoTarget' (タイプ 'Object') です
テンプレートの残りの部分の一般的な考え方は次のとおりです。
<ControlTemplate x:Key="LocalHelpWindow">
<Grid>
<Grid.RowDefinitions>
...
</Grid.RowDefinitions>
<help:AdornedPlaceholder x:Name="adorner" Grid.Row="0"/>
<Border Grid.Row="1" x:Name="mainBorder">
...
</Border>
</Grid>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding ElementName=adorner, Path=AdornedElement.IsChecked}" Value="True" >
...
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>