Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I have an animation that fades in and fades out a control on my View. I initiate the animations by setting boolean values in the View Model of the application.

HTML
<border.style>>
									<Style>
										<Style.Triggers>
											<DataTrigger Binding="{Binding FadeIn}" Value="True">
												<DataTrigger.EnterActions>
													<BeginStoryboard>
														<Storyboard >
															<DoubleAnimation Duration="0:0:0.5"
															                 Storyboard.TargetProperty="Opacity"
															                 To="1" />
														</Storyboard>
													</BeginStoryboard>
												</DataTrigger.EnterActions>
												<DataTrigger.ExitActions>
													<BeginStoryboard>
														<Storyboard>
															<DoubleAnimation Duration="0:0:1"
															                 Storyboard.TargetProperty="Opacity"
															                 To="0" />
														</Storyboard>
													</BeginStoryboard>
												</DataTrigger.ExitActions>
											</DataTrigger>											
										</Style.Triggers>
									</Style>
								</Border.Style>


If the user moves their mouse over the control when it's fading out however, I would like to pause the animation, display the control with maximum opacity and then when the mouse leaves the area, continue the animation.

I've tried a few things, but I can't see how to pause an animation in XAML.

Cheers for any help

Larry
Posted
Comments
Laurence1234 10-Aug-11 10:03am    
ok, I can now pause the animation, but it pauses at whatever opacity it has got to rather then returning to 100% instantly then resuming the fade out once the mouse leaves.

1 solution

Hi, Larry;

I came across the following link in MSDN that may be of help:

http://msdn.microsoft.com/en-us/library/system.windows.media.animation.pausestoryboard.aspx

The XAML example at the bottom of the page is fully self-contained, and should work as is in either Visual Studio 2010 or in Kaxamal http://www.kaxamal.com

The storyboard pause and behaviors are implemented through a routed events bound to respective Button clicks, but I think they could be bound to any mouse event.

As for resuming the storyboard playback, having the opacity pick up where the pause click I would think is the correct default behavior, and to have the opacity set to 100% may require an additional data binding to set the opacity back to 100% when resumed.

I hope this was of help and of interest, and once you have the XAML working, I think it would be of tremendous value if you could share your results with us.
 
Share this answer
 
Comments
Laurence1234 15-Aug-11 4:56am    
Hi,

Thanks for the response. I will indeed, if I ever figure it out, post it up. For now I'll take a look at this link.

Cheers

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900