我在这里有点困惑,所以请帮帮我。
我有一个简单的wpf动画:
<DropShadowEffect Color="Transparent" ShadowDepth="0" Opacity="0.75" x:Key="Shiny" x:Shared="False"/>
<Storyboard x:Key="ShinyAnim" x:Shared="False">
<ColorAnimation From="Transparent" To="Red" Duration="0:0:1" Storyboard.TargetProperty="(Effect).Color" />
<DoubleAnimationUsingKeyFrames RepeatBehavior="Forever" Storyboard.TargetProperty="(Effect).BlurRadius" AutoReverse="True">
<DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="1"/>
<DiscreteDoubleKeyFrame KeyTime="0:0:0.15" Value="2"/>
<DiscreteDoubleKeyFrame KeyTime="0:0:0.3" Value="3"/>
<DiscreteDoubleKeyFrame KeyTime="0:0:0.45" Value="4"/>
<DiscreteDoubleKeyFrame KeyTime="0:0:0.6" Value="5"/>
<DiscreteDoubleKeyFrame KeyTime="0:0:0.75" Value="6"/>
<DiscreteDoubleKeyFrame KeyTime="0:0:0.9" Value="7"/>
<DiscreteDoubleKeyFrame KeyTime="0:0:1.05" Value="8"/>
<DiscreteDoubleKeyFrame KeyTime="0:0:1.2" Value="9"/>
<DiscreteDoubleKeyFrame KeyTime="0:0:1.35" Value="10"/>
<DiscreteDoubleKeyFrame KeyTime="0:0:1.5" Value="11"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Style x:Key="AnimShape" TargetType="Shape">
<Setter Property="Stroke" Value="DarkGray"/>
<Setter Property="Effect" Value="{StaticResource Shiny}/>
<Style.Triggers>
<DataTrigger Binding="{Binding HasChannelWarnings}" Value="True">
<Setter Property="Stroke" Value="Red"/>
<DataTrigger.EnterActions>
<BeginStoryboard x:Name="ChannelAnim" Storyboard="{StaticResource ShinyAnim}"/>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<RemoveStoryboard BeginStoryboardName="ChannelAnim"/>
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
如果我用这种风格加载控件,而HasChannelWarnings == false - 一切正常:当属性改变时 - 我得到闪亮的动画。但是,如果我加载控件,当HasChannelWarnings == true时,我收到错误:
无法解析属性路径中的所有属性引用'(Effect).Color'。验证适用的对象是否支持属性。
有人可以解释我的最新情况吗?在效果设定器之前是否触发?如果是这样,如何正确应用此动画?
答案 0 :(得分:0)
我通过将触发器更改为多重触发器来解决这个问题
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding HasChannelWarnings}" Value="True">
<Condition Binding="{Binding Effect, RelativeSource={RelativeSource Mode=Self}, Converter={Converters:IsNullConverter}}" Value="False"/>
</MultiDataTrigger.Conditions>
但我真的不喜欢这个解决方案。必须有更好的方法。