How can I use a DataTrigger to run a storyboard?

This is my first question asking a question here, and it is on the topic. I am a newbie, so please carry me here.

I am developing a WPF GUI application with MVVM architecture, and the approach we take with my team is to have several views that will have to “fly on and off” on the screen when the user interface goes through its movements. The problem we are facing is how to start the animation while the user interface moves from one view to another. I have a button on my main view that, when clicked, a property changes that allows one view to know that it needs to leave, and I'm trying to snap it to the beginning of my animation. I have timers that delay the change of view for the duration of my storyboard animation, but I can't get my animation to work!In XAML, I have my own storyboard set (generated in Blend) in a DataTrigger as follows:

<UserControl.Style>
   <Style>
      <Style.Triggers>
         <DataTrigger Binding="{Binding StandbyViewModel.LeavingStandbyView}" Value="true">
            <BeginStoryboard>
               <Storyboard>
                  <DoubleAnimationUsingKeyFrames ...> // I've got 22 of these statements in my storyboard

I'm having problems with DoubleAnimationUsingKeyFrames lines with the Storyboard.TargetName = "label" property, which is generated by Blend, which refers to every part of the user interface that I animate. The error I am getting is:

TargetName property cannot be set on a Style Setter

It looks like I'm not allowed to use the TargetName property here, but how else can I specify which animation maps for the UI component? I have 7 user interface elements that I move and change the opacity during the 0.5 second animation I created, so I imagine that I have to have a way to identify each of them.

, - ? , , . , , UserControl , .

.

+4
1

, , , DataTrigger.EnterActions , , :

<UserControl.Style>
   <Style>
      <Style.Triggers>
         <DataTrigger Binding="{Binding StandbyViewModel.LeavingStandbyView}" Value="true">
             <DataTrigger.EnterActions>
                <BeginStoryboard>
                   <Storyboard>
                      <DoubleAnimationUsingKeyFrames ...> 
+1

Source: https://habr.com/ru/post/1524615/


All Articles