私のプロジェクトでは、WPF のほとんどのスタイルを作成するための単一のファイルがあります。TextBlock の背景を設定し、その ViewBox をアニメーション化してカルーセル効果を与えようとしています。アプリケーションのロード時にすべてのコントロールが存在する場合、私は成功しました。ただし、新しいトリガーに一致するコントロールを追加した直後に、例外がスローされます。これが私のコードです
<Style TargetType="{x:Type TextBlock}">
<!-- Image Carousal -->
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=4},Path=Name}" Value="WelcomeScreen_Master" />
<Condition Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Grid}}, Path=Name}" Value="LayoutMainTitleGrid" />
<Condition Binding="{Binding RelativeSource={RelativeSource Self},Path=Name}" Value="Banner"/>
</MultiDataTrigger.Conditions>
<MultiDataTrigger.Setters>
<Setter Property="Width" Value="400" />
<Setter Property="Height" Value="146" />
<Setter Property="Foreground" Value="Transparent"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="Margin" Value="620,200,0,0" />
<Setter Property="Background">
<Setter.Value>
<ImageBrush
ImageSource="pack://application:,,,/LoremTheme;component/images/rotate.png"
Stretch="UniformToFill"
AlignmentY="Top"
AlignmentX="Right"
ViewboxUnits="Absolute" Viewbox="0,0,400,146"
ViewportUnits="Absolute" Viewport="0,0,300,109.5"
>
</ImageBrush>
</Setter.Value>
</Setter>
</MultiDataTrigger.Setters>
<MultiDataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<RectAnimation Storyboard.TargetProperty="Background.Viewbox"
To="0,0,400,146" BeginTime="0:0:5" Duration="0:0:0.1" />
</Storyboard>
</BeginStoryboard>
</MultiDataTrigger.EnterActions>
</MultiDataTrigger>
</Style.Triggers>
</Style>
コードでTextBlockの背景画像を設定するとコードは機能しますが、アプリケーションには異なるスタイルファイルがあるため、オプションではありません。私が削除した場合上記のスタイルから、アニメーションなしで境界線を設定できます。これは、xaml が背景を設定できることを意味します。しかし、私が維持する場合次の例外が発生します。
---------------------------
Active Window : Exception
---------------------------
Method:Void VerifyPathIsAnimatable(System.Windows.PropertyPath)
System.InvalidOperationException: Cannot resolve all property references in the property path 'Background.Viewbox'. Verify that applicable objects support the properties.
at System.Windows.Media.Animation.Storyboard.VerifyPathIsAnimatable(PropertyPath path)
at System.Windows.Media.Animation.Storyboard.ClockTreeWalkRecursive(Clock currentClock, DependencyObject containingObject, INameScope nameScope, DependencyObject parentObject, String parentObjectName, PropertyPath parentPropertyPath, HandoffBehavior handoffBehavior, HybridDictionary clockMappings, Int64 layer)
アニメーションを機能させるにはどうすればよいですか? 現在、スタイルが背景を設定する前にアニメーションが開始されていると想定しているため、ストーリーボードを遅らせる方法はありますか? または別の解決策がありますか?