我有XAML这样的触发器:
<UserControl.Style>
<Style TargetType="UserControl">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Path=Visible}" Value="True" />
<Condition Binding="{Binding Path=AnimationEnabled}" Value="True" />
</MultiDataTrigger.Conditions>
<MultiDataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0:0:0.000"
Value="{x:Static Visibility.Visible}"/>
</ObjectAnimationUsingKeyFrames>
<ThicknessAnimation Storyboard.TargetProperty="Margin" Duration="0:0:0.200"
From="0,570,0,-570" To="0,0,0,-1">
<ThicknessAnimation.EasingFunction>
<QuadraticEase EasingMode="EaseOut"/>
</ThicknessAnimation.EasingFunction>
</ThicknessAnimation>
</Storyboard>
</BeginStoryboard>
</MultiDataTrigger.EnterActions>
<MultiDataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<ThicknessAnimation Storyboard.TargetProperty="Margin" Duration="0:0:0.200"
From="0,0,0,0" To="0,570,0,-570">
<ThicknessAnimation.EasingFunction>
<QuadraticEase EasingMode="EaseIn"/>
</ThicknessAnimation.EasingFunction>
</ThicknessAnimation>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0:0:0.200"
Value="{x:Static Visibility.Collapsed}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</MultiDataTrigger.ExitActions>
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Path=Visible}" Value="True" />
<Condition Binding="{Binding Path=AnimationEnabled}" Value="False" />
</MultiDataTrigger.Conditions>
<MultiDataTrigger.Setters>
<Setter Property="Visibility" Value="{x:Static Visibility.Visible}" />
<Setter Property="Margin" Value="0,0,0,-1" />
</MultiDataTrigger.Setters>
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Path=Visible}" Value="False" />
<Condition Binding="{Binding Path=AnimationEnabled}" Value="False" />
</MultiDataTrigger.Conditions>
<MultiDataTrigger.Setters>
<Setter Property="Visibility" Value="{x:Static Visibility.Hidden}" />
<Setter Property="Margin" Value="0,570,0,-570" />
</MultiDataTrigger.Setters>
</MultiDataTrigger>
</Style.Triggers>
</Style>
</UserControl.Style>
</UserControl>
我的想法是,如果启用动画,我会显示动画。 但如果不是,我想简单地移动或使事物可见/隐藏而不是动画。
我的例子不起作用。我认为这是因为我还没有为Setter声明TargetName。但我不想这样做,因为我希望我的属性应用与Style相同。
我该怎么做才能使这项工作?