在我的项目中,我有一个文件来创建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)
如何让动画有效?现在我的假设是动画在样式设置背景之前开始,所以有没有办法延迟故事板?还是有另一种解决方案?