Start storyboard in the next schedule scale

I have a storyboard (1) that performs some basic animations in 2 seconds. I want the storyboard (1) to perform all the property animations that I set for it (all this works great). But after 3 seconds in the storyboard (1) I want to start the storyboard (2) and exit the storyboard (1) without any interaction with the user at all.

The only thing I saw that allows me to do this is when the user clicks on something. I want this to be automatic based on the position of the current timeline (1).

Hope this makes sense. Please let me know if you need me to explain something in more detail.

Thanks.

Edit: send the answer in XAML or VB.net. :)

+4
source share
3 answers

Well, I came up with a solution. I just spawned a new thread to wait 3 seconds and then called a call to start the storyboard from that thread.

Dim board As Storyboard = New Storyboard board = DirectCast(TryFindResource("DoSplit"), Storyboard) If board IsNot Nothing Then board.Begin(Me, True) Dim t As Thread t = New Thread(AddressOf Me.WaitToHidePanel) t.SetApartmentState(ApartmentState.STA) t.Start() End If 

Make your threads safe delegates and features and you will work. This, in my opinion, is an ugly hack, but now it works.

0
source

Typically, you use β€œkey frames” to control the animation during the timeline. Keyframe animation allows you to define specific values ​​for a property that you are animating at a specific time. In WPF, each animation has a corresponding keyframe animation, for example, "DoubleAnimation" has a "DoubleAnimationUsingKeyFrames".

I don’t think you can start a new storyboard inside the animation. However, you could achieve the same result, having both storyboards on the same timeline and the initial storyboard (2) with a certain delay depending on the duration of the storyboard (1). Sort of:

 <StackPanel> <Rectangle Name="recProgressBar" Fill="Orange" Width="1" Height="25" Margin="20" HorizontalAlignment="Left" /> <Button Content="Start Animation" Width="150" Height="25"> <Button.Triggers> <EventTrigger RoutedEvent="Button.Click"> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="recProgressBar" Storyboard.TargetProperty="Width" From="0" To="250" Duration="0:0:2" /> <Storyboard BeginTime="0:0:3"> <ColorAnimation Storyboard.TargetName="recProgressBar" Storyboard.TargetProperty="Fill.Color" To="DarkGreen" Duration="0:0:1" /> </Storyboard> </Storyboard> </BeginStoryboard> </EventTrigger> </Button.Triggers> </Button> </StackPanel> 

Here the color animation starts 1 second after the width animation finishes. Maybe worth a try.

+6
source

Thanks Megakemp for what I was afraid to do. I did not want to manage two copies of the storyboard in XAML. If I need to add a control and manage it through the storyboard (1), I will have to remember to copy and paste the changes to this other storyboard (2). I suppose these are hoops that you should jump until the functionality that I am looking for appears.

Now I was thinking of another idea to try, but could not get the functionality. This is my idea below, I can explain it better in the code .. this code below will not compile, just to understand my point.

 Dim board As Storyboard = New Storyboard board = DirectCast(TryFindResource("Animation1"), Storyboard) If board IsNot Nothing Then board.Begin(Me) While board.GetCurrentState(Me) = ClockState.Active 'Wait until Animation1 ends End While 'Start Animation2 board = DirectCast(TryFindResource("Animation2"), Storyboard) If board IsNot Nothing Then board.Begin(Me) End If End If 

Thank you for your help .. and if anyone else has a different answer or more detailed information, please feel free to post, I do not completely abandon this idea.

0
source

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


All Articles