0

我如何有条件地让这个动画运行,取决于 a bool CanAnimate?它现在可以工作,但我并不总是希望它是动画的,我想检查布尔值。

<Border BorderBrush="Black" BorderThickness="2" Margin="1" Name="ReviewNote">
   <Border.Triggers>
      <EventTrigger RoutedEvent="Border.Loaded">
         <BeginStoryboard>
            <Storyboard>
               <DoubleAnimation 
                    Storyboard.TargetName="ReviewNote"
                    Storyboard.TargetProperty="(Border.Opacity)"
                    From="1.0" To="0.0" AutoReverse="True" RepeatBehavior="Forever" />
            </Storyboard>
         </BeginStoryboard>
      </EventTrigger>
   </Border.Triggers>
   <TextBlock Text="{x:Static Constants:StringConstants.ReviewNote}" 
              Background="{StaticResource ReviewNoteColor}" Width="100" 
              TextAlignment="Center" />
</Border>
4

1 回答 1

2

在边框和内部样式上应用样式,您可以检查 bool 属性的值。基于该属性,您可以DataTrigger.EnterActions在从 storyBoard 中删除 TargetName 后使用 storyboard 指定。

这将起作用 -

<Border BorderBrush="Black" BorderThickness="2" Margin="1" Name="ReviewNote">
    <Border.Style>
        <Style TargetType="Border">
           <Style.Triggers>
               <DataTrigger Binding="{Binding CanAnimate}" Value="True">
                   <DataTrigger.EnterActions>
                       <BeginStoryboard>
                           <Storyboard>
                              <DoubleAnimation 
                                    Storyboard.TargetProperty="(Border.Opacity)"
                                    From="1.0" To="0.0" AutoReverse="True" 
                                    RepeatBehavior="Forever" />
                            </Storyboard>
                       </BeginStoryboard>
                   </DataTrigger.EnterActions>
               </DataTrigger>
            </Style.Triggers>
         </Style>
    </Border.Style>
   <TextBlock/>
</Border>
于 2013-11-04T22:10:25.240 回答