PlaTyPuS8

Hi!

I've an image (logo of ActiveSync in fact ) and want that this one turn on itself at the begining of a process and stop turning when the process is finished.

Do somebody have such an example

Thanks for help!

++

PlaTyPuS



Re: Windows Presentation Foundation (WPF) Animate an image and stop animation when process is finished

Frances83

Do you want an example of the animation or of starting / stopping the animation




Re: Windows Presentation Foundation (WPF) Animate an image and stop animation when process is finished

PlaTyPuS8

of the continuous animation

(--> I already made an animation (with Blend).... but can't make it continuous...)

for the start and stop, I think I can manage it myself...





Re: Windows Presentation Foundation (WPF) Animate an image and stop animation when process is finished

Drew Marsh

You should just need to set the RepeatBehavior="Forever" on your animation.

HTH,
Drew





Re: Windows Presentation Foundation (WPF) Animate an image and stop animation when process is finished

PlaTyPuS8

ohhh very simple

thx!!

do you know how I can stop it in code-behind





Re: Windows Presentation Foundation (WPF) Animate an image and stop animation when process is finished

PlaTyPuS8

up



Re: Windows Presentation Foundation (WPF) Animate an image and stop animation when process is finished

Yi-Lun Luo - MSFT

yourAnimation.RepeatBehavior = RepeatBehavior.Forever;

Sorry, I didn't read your post carefully. Well, if you want to stop the animation, here's a sample:

http://msdn2.microsoft.com/en-us/library/ms741997.aspx






Re: Windows Presentation Foundation (WPF) Animate an image and stop animation when process is finished

PlaTyPuS8

hi! thx for the reply!

My animation is done in the XAML file.... and I want to stop it from another c# class!

Code Snippet

Footer.xaml <-- my animation is here

Footer.cs

Synchonisation.cs <-- I want to stop the animation from here...

Do you have an idea how I can get it work

Thx!!!

edit: I tried with a static method, but the storyboard name (in xaml) isn't static.....





Re: Windows Presentation Foundation (WPF) Animate an image and stop animation when process is finished

PlaTyPuS8

little up....



Re: Windows Presentation Foundation (WPF) Animate an image and stop animation when process is finished

Drew Marsh

There's a million things that make this impossible to answer without more details.

If your storyboard is defined as a resource of the window, you should be able to do something like this:

Code Snippet

Storyboard storyboard = (Storyboard)this.FindResource("myStoryboardKey");

storyboard.Stop(this);

Where "this" above is your Window.

HTH,
Drew





Re: Windows Presentation Foundation (WPF) Animate an image and stop animation when process is finished

PlaTyPuS8

thanks for help, but I can't get it work....

I explain my problem with more details :

Code Snippet

Footer.xaml <-- Is a UserControl (\ToDoElements\Footer.xaml)

Footer.xaml.cs

<UserControl.Resources>

<ResourceDictionary>

<Storyboard x:Key="SynchronizationAnim">

<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" RepeatBehavior="Forever" Storyboard.TargetName="syncImage" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">

<SplineDoubleKeyFrame KeyTime="00:00:01" Value="360" />

</DoubleAnimationUsingKeyFrames>

</ResourceDictionary>

</UserControl.Resources>

When the user clicks on the "syncImage" I'm launching the animation with triggers, and in code-behind I start a synchronization process. This sync-process is contained in Synchronization.cs class (not a window!) (\app\Synchronization.cs).

When the sync-process is finished I want to stop the animation!

I tried to make it with static method in Footer.xaml.cs, but it returns me this error : The calling thread cannot access this object because a different thread owns it.

Thx for help





Re: Windows Presentation Foundation (WPF) Animate an image and stop animation when process is finished

Frances83

To access a resource from a different thread:


Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(YourMethod), null);


The function would look something like this:

private object YourMethod(object obj)
{
// do something...

return null;
}





Re: Windows Presentation Foundation (WPF) Animate an image and stop animation when process is finished

PlaTyPuS8

Frances83 wrote:
To access a resource from a different thread:


Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(YourMethod), null);


The function would look something like this:

private object YourMethod(object obj)
{
// do something...

return null;
}

Hi! I tried it but have the following error :

The calling thread must be STA, because many UI components require this.

My method (in Footer.xaml - Footer.xaml.cs)

Code Snippet

public object stopSyncAnimation(object o)

{

SynchronizationAnim_BeginStoryboard1.Storyboard.Stop(this);

return null;

}

And the call (from Synchronization.cs)

Code Snippet

Footer footer = Footer.getInstance();

Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(footer.stopSyncAnimation), null);

Thanks





Re: Windows Presentation Foundation (WPF) Animate an image and stop animation when process is finished

Drew Marsh

Theoretcially you should use footer.Dispatcher instead of Application.Current.Dispatcher since they could be different. Slim chance that's your problem though, unless you were creating your own Dispatcher threads, so that call should most definitely work.

That said, to be honest, I think you're going in the wrong direction and that's why you're feeling the pain. You're tightly coupling your UI with your business logic code and that's what you want to try and avoid with WPF. The approach I would try is to just raise an event out of your control when the synchronization is finished and stop the Storyboard using an EventTrigger.

HTH,
Drew





Re: Windows Presentation Foundation (WPF) Animate an image and stop animation when process is finished

PlaTyPuS8

Drew Marsh wrote:

That said, to be honest, I think you're going in the wrong direction and that's why you're feeling the pain. You're tightly coupling your UI with your business logic code and that's what you want to try and avoid with WPF. The approach I would try is to just raise an event out of your control when the synchronization is finished and stop the Storyboard using an EventTrigger.

HTH,
Drew

Thanks for this suggestion, but do you think it is possible to change a simple Property when the synchronization process is finished and use an EventTrigger that is bind to this Property

I suggest that because, I don't understand your suggestion of "raising an event out of the control....."

thx!