Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to run a story board, and then remove it after it has finished

$
0
0

Hi, I wanted to be able to change the Background of a button when it is clicked, have this colour stay applied for say 3 seconds, and then the background revert to the original.

I am using a Style for this button, so if I didn't nbeed this delay, then I could just use

<Trigger Property="IsPressed" Value="True"><Setter Property="Background" Value="{DynamicResource PressedColour}" /></Trigger>

Since I need this delay, I have been trying to use a StoryBoard, using something like..

<EventTrigger RoutedEvent="UIElement.PreviewMouseLeftButtonDown"><EventTrigger.Actions><BeginStoryboard Name="myBeginStoryboard" ><Storyboard AutoReverse="True"><ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:03:00"  Storyboard.TargetProperty="(Button.Background)"><DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{StaticResource PressedColour}"/>                                   </ObjectAnimationUsingKeyFrames></Storyboard></BeginStoryboard></EventTrigger.Actions>                    </EventTrigger>

Now all I want is to be able to Remove this storyBook once it has finished

I tried using a RemoveStoryBook in the

<EventTrigger RoutedEvent="UIElement.PreviewMouseLeftButtonUp">

However, this does not wait for the duration of the storybook to complete, it just removes it as soon as we  mouse up.

Also, I could not just set another object animation, eg

<EventTrigger RoutedEvent="UIElement.PreviewMouseLeftButtonDown"><EventTrigger.Actions><BeginStoryboard Name="myBeginStoryboard" ><Storyboard AutoReverse="True"><ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:03:00"  Storyboard.TargetProperty="(Button.Background)"><DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{StaticResource PressedColour}"/>                                   </ObjectAnimationUsingKeyFrames><ObjectAnimationUsingKeyFrames BeginTime="00:00:02" Duration="00:0:00"  Storyboard.TargetProperty="(Button.Background)"><DiscreteObjectKeyFrame KeyTime="00:00:02" Value="{StaticResource OriginalBackColour}"/></ObjectAnimationUsingKeyFrames></Storyboard></BeginStoryboard></EventTrigger.Actions>                    </EventTrigger>

since the OriginalBackColour is a *Dynamic* application wide resource.

I am after the storybook just to remove itself after it has finished playing. IS there a way to do this?

Thanks in advance for any information

Peter


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>