Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Associating an Animation::Completed event with an object

 
 
Old 11-21-2006   #1 (permalink)
John Dunn


 
 

Associating an Animation::Completed event with an object

Is there an easy way to associate an EventHandler attached to the animation
Completed event with the object that BeginAnimation was initially called?

I need to run some cleanup code after my animation finishes. I've attached a
handler to the Completed event but I can't find any useful context in the Object
which is passed into the handler. The object is an Animation::AnimationClock but
nowhere in the debugger can I find the Object that I called BeginAnimation from.

I guess I could set up a callback on a timer to call the cleanup function but it
seemed like it should be possible to hook into the Animation system to get this
information.

here's some psuedo code of what i'd like to do

void anim_done( Object sender, EventArgs args ) {
// somehow get the handle to the my_object instance here
my_object.cleanup();
}

void my_object::start_anim() {
DoubleAnimation anim = new DoubleAnimation();
anim.From = 1;
anim.To = 0;
anim.Duration = 150;
anim.Completed += anim_done;
BeginAnimation( Opacity, anim );
}

Thanks-

John



My System SpecsSystem Spec
Old 11-22-2006   #2 (permalink)
Stoitcho Goutsev \(100\)


 
 

Re: Associating an Animation::Completed event with an object

John,
Isn't it anim_done member of the my_object class? If it is the reference to
the object is *this*.


--
Stoitcho Goutsev (100)

"John Dunn" <jhndnn@community.nospam> wrote in message
news:Ot4BkSZDHHA.4024@TK2MSFTNGP04.phx.gbl...
> Is there an easy way to associate an EventHandler attached to the
> animation Completed event with the object that BeginAnimation was
> initially called?
>
> I need to run some cleanup code after my animation finishes. I've attached
> a handler to the Completed event but I can't find any useful context in
> the Object which is passed into the handler. The object is an
> Animation::AnimationClock but nowhere in the debugger can I find the
> Object that I called BeginAnimation from.
>
> I guess I could set up a callback on a timer to call the cleanup function
> but it seemed like it should be possible to hook into the Animation system
> to get this information.
>
> here's some psuedo code of what i'd like to do
>
> void anim_done( Object sender, EventArgs args ) {
> // somehow get the handle to the my_object instance here
> my_object.cleanup();
> }
>
> void my_object::start_anim() {
> DoubleAnimation anim = new DoubleAnimation();
> anim.From = 1;
> anim.To = 0;
> anim.Duration = 150;
> anim.Completed += anim_done;
> BeginAnimation( Opacity, anim );
> }
>
> Thanks-
>
> John
>
>



My System SpecsSystem Spec
Old 11-27-2006   #3 (permalink)
John Dunn


 
 

Re: Associating an Animation::Completed event with an object

Stoitcho Goutsev (100) wrote:
> John,
> Isn't it anim_done member of the my_object class? If it is the reference to
> the object is *this*.
>
>


My code is C++/CLI so the anim_done method is actually a static function. In
that case the object is a System::Windows::Media::Animation::AnimationClock
handle. Here's my C++ code-


static void close_anim_done( Object^ obj, EventArgs^ args ) {
// do something here
}

void window_t::close() {
Animation:oubleAnimation^ sanim = gcnew
Animation:oubleAnimation(1,0,Duration( TimeSpan::FromMilliseconds( 150 )));
sanim->Completed += gcnew EventHandler( close_anim_done );
BeginAnimation( OpacityProperty, sanim );
}
My System SpecsSystem Spec
Old 11-27-2006   #4 (permalink)
John Dunn


 
 

Re: Associating an Animation::Completed event with an object

John Dunn wrote:
> Stoitcho Goutsev (100) wrote:
>> John,
>> Isn't it anim_done member of the my_object class? If it is the
>> reference to the object is *this*.
>>
>>

>
> My code is C++/CLI so the anim_done method is actually a static
> function. In that case the object is a
> System::Windows::Media::Animation::AnimationClock handle. Here's my C++
> code-
>
>
> static void close_anim_done( Object^ obj, EventArgs^ args ) {
> // do something here
> }
>
> void window_t::close() {
> Animation:oubleAnimation^ sanim = gcnew
> Animation:oubleAnimation(1,0,Duration( TimeSpan::FromMilliseconds( 150
> )));
> sanim->Completed += gcnew EventHandler( close_anim_done );
> BeginAnimation( OpacityProperty, sanim );
> }


Never mind, I just figured out if I use the other signature for the EventHandler
constructor I can pass in a pointer along with a pointer to a member function.
That works fine.
My System SpecsSystem Spec
Old 12-08-2006   #5 (permalink)
Stoitcho Goutsev \(100\)


 
 

Re: Associating an Animation::Completed event with an object

Yes, this is what C# anonyimous methods does automatically for us, but if
you use c++ I guess you need to do it by yourself.


--
Stoitcho Goutsev (100)

"John Dunn" <jhndnn@community.nospam> wrote in message
news:ugY8PcmEHHA.4048@TK2MSFTNGP02.phx.gbl...
> John Dunn wrote:
>> Stoitcho Goutsev (100) wrote:
>>> John,
>>> Isn't it anim_done member of the my_object class? If it is the reference
>>> to the object is *this*.
>>>
>>>

>>
>> My code is C++/CLI so the anim_done method is actually a static function.
>> In that case the object is a
>> System::Windows::Media::Animation::AnimationClock handle. Here's my C++
>> code-
>>
>>
>> static void close_anim_done( Object^ obj, EventArgs^ args ) {
>> // do something here
>> }
>>
>> void window_t::close() {
>> Animation:oubleAnimation^ sanim = gcnew
>> Animation:oubleAnimation(1,0,Duration( TimeSpan::FromMilliseconds(
>> 150 )));
>> sanim->Completed += gcnew EventHandler( close_anim_done );
>> BeginAnimation( OpacityProperty, sanim );
>> }

>
> Never mind, I just figured out if I use the other signature for the
> EventHandler constructor I can pass in a pointer along with a pointer to a
> member function. That works fine.



My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Associating MDB to MS Access Microsoft Office
Is there a SELECTION-COMPLETED event for DATAGRIDVIEWS??? .NET General
Object lifetime/event problem .NET General
Adding canonical aliases for Compare-Object, Measure-Object, New-Object PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46