属性更改时XAML中的EventTrigger?

时间:2013-03-26 00:05:24

标签: wpf xaml inotifypropertychanged eventtrigger

我有这段代码(到目前为止它正在运行);

<Image Name="img_person" Tag="{Binding Path=MyProperty1, NotifyOnTargetUpdated=True}" Canvas.Top="0" Canvas.Left="0">
  <Image.Triggers>
    <EventTrigger RoutedEvent="Binding.TargetUpdated">
      <BeginStoryboard>
        <Storyboard>
          <DoubleAnimation 
            Storyboard.TargetName="img_person" 
            Storyboard.TargetProperty="(Canvas.Top)" 
            By="64"
            Duration="0:0:0.8"
            AutoReverse="False" />
       </Storyboard>
     </BeginStoryboard>
   </EventTrigger>
 </Image.Triggers>

我想改变这一行;

    <EventTrigger RoutedEvent="Binding.TargetUpdated">

这样的事情;

    <EventTrigger ThisParticularPropertyHasChanged="MyProperty1">

我想这样做,因为我将有几个故事板,每个故事板在特定属性更改时启动。有一个属性我已经将它绑定到图像的Tag属性,但现在我有几个要做(大约8个)我不知道该怎么做。

该类实现INotifyPropertyChanged。

感谢。

解决方案,多亏了sa_ddam213;

    <Style x:Key="PersonImageStyle" TargetType="{x:Type Image}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding UI_DirectionOfMovement}" Value="South">
                <DataTrigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetProperty="(Canvas.Top)" By="64" Duration="0:0:0.8" AutoReverse="False" />
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.EnterActions>
            </DataTrigger>
            <DataTrigger Binding="{Binding UI_DirectionOfMovement}" Value="East">
                <DataTrigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetProperty="(Canvas.Left)" By="64" Duration="0:0:0.8" AutoReverse="False" />
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.EnterActions>
            </DataTrigger>
        </Style.Triggers>
    </Style>

0 个答案:

没有答案