locked
TimeLine listener (obalu) - 8/29/2006 2:56 PM PST RRS feed

  • Question

  • By: obalu

    Hi,
    
    How is it posibble to issue commands form a given Timeline Position?
    E.G I have a page with 4 images, and whichever the user clicks on will 
    "grow" untill it reaches full size. This is the point where I would like to 
    switch to another page.
    I know, this problem can be solved with the animation on the new page, but 
    some other examples could not. 
    I've read a word about timeline listeners in another post. What are these?
    
    Thanks,
    
    Balint
    
    Tuesday, February 19, 2008 1:56 AM

Answers

  • By: Michael G. Emmons
    For most XAML objects (that is, objects which are defined in the .xaml file,
    not ones defined in the .xaml.cs file) you need to get a reference to them
    using FindResource. To get a reference to your timeline issue the following:

    Storyboard myStoryBoard = (Storyboard)this.FindResource("Timeline1");



    "obalu" <obalu@discussions.microsoft.com> wrote in message
    news:75C252C4-CD66-40B8-90D1-D7C6B1C7E2E4@microsoft.com...
    > Thanks, it helped a lot, but I still can't quite figure it out.
    > At a MSDN example
    >
    http://windowssdk.msdn.microsoft.com/en-us/library/ms741973.aspx
    > I saw, that in a function he can call myStoryboard.
    > But if I try it in my project with Timeline1(which is an existing
    > timeleine), E.G
    > ..
    > Timeline1.Begin();
    >
    > I get the error message when compiling:
    > "The name 'Timeline1' does not exist in the current context.
    >
    > What could be the problem?
    > Thanks,
    >
    > Balint
    >
    > "Beta Tester" wrote:
    >
    >> The only timeline related event triggers that can be captured are
    >> begin/end/pause/resume. The xaml would look something like:
    >>
    >> <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="Button">
    >> <BeginStoryboard Storyboard="{StaticResource Timeline1}"
    >> x:Name="Timeline1_BeginStoryboard"/>
    >> </EventTrigger>
    >>
    >> In code this would be the equivalent of:
    >>
    >> myButton.Click += delegate(object sender, RoutedEventArgs args)
    >> {
    >> myStoryboard.Begin(myButton);
    >> };
    >>
    >>
    >> If you look at the storyboard class you will see that it has a Completed
    >> event. Presumably this fires whenever the storyboard completes the
    >> animation. Subscribing to this event you could do whatever you need to do
    >> once the animation completes:
    >>
    >> ....
    >> {
    >> ....
    >> Storyboard story = new Storyboard();
    >> story.Completed += new EventHandler(story_Completed);
    >> }
    >>
    >> void story_Completed(object sender, EventArgs e)
    >> {
    >> // Do whatever needs to be done when animation is complete
    >> }
    >>
    >> There is also another couple of interesting event handlers:
    >> CurrentStateInvalidated and CurrentTimeInvalidated.
    >> CurrentStateInvalidated
    >> will fire whenver the timelines CurrentState property of the timeline's
    >> clock is updated. CurrentTimeInvalidated fires whenever the CurrentTime
    >> propery of the timeline's clock is updated. Figuring out exactly what the
    >> current state of the clock represents can be a little tricky, take a look
    >> at
    >>
    http://windowssdk.msdn.microsoft.com/en-us/library/system.windows.media.animation.clockstate.aspx.
    >> It has some good graphics that detail exactly what happens when.
    >>
    >>
    >> I've also read that the timeline's clock is directly controllable. So,
    >> you
    >> should be able to set it anywhere in the timeline you want, manually.
    >>
    >> Hope this helps!
    >>
    >> Michael G. Emmons
    >>
    http://xamlxaml.com
    >>
    >>
    >> "obalu" <obalu@discussions.microsoft.com> wrote in message
    >> news:ACDB1055-F7C4-4FBA-879E-5D6BCC4CA4B8@microsoft.com...
    >> > Hi,
    >> >
    >> > How is it posibble to issue commands form a given Timeline Position?
    >> > E.G I have a page with 4 images, and whichever the user clicks on will
    >> > "grow" untill it reaches full size. This is the point where I would
    >> > like
    >> > to
    >> > switch to another page.
    >> > I know, this problem can be solved with the animation on the new page,
    >> > but
    >> > some other examples could not.
    >> > I've read a word about timeline listeners in another post. What are
    >> > these?
    >> >
    >> > Thanks,
    >> >
    >> > Balint
    >> >
    >>
    >>


    Tuesday, February 19, 2008 6:22 PM

All replies

  • By: Beta Tester
    The only timeline related event triggers that can be captured are
    begin/end/pause/resume. The xaml would look something like:

    <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="Button">
    <BeginStoryboard Storyboard="{StaticResource Timeline1}"
    x:Name="Timeline1_BeginStoryboard"/>
    </EventTrigger>

    In code this would be the equivalent of:

    myButton.Click += delegate(object sender, RoutedEventArgs args)
    {
    myStoryboard.Begin(myButton);
    };


    If you look at the storyboard class you will see that it has a Completed
    event. Presumably this fires whenever the storyboard completes the
    animation. Subscribing to this event you could do whatever you need to do
    once the animation completes:

    ....
    {
    ....
    Storyboard story = new Storyboard();
    story.Completed += new EventHandler(story_Completed);
    }

    void story_Completed(object sender, EventArgs e)
    {
    // Do whatever needs to be done when animation is complete
    }

    There is also another couple of interesting event handlers:
    CurrentStateInvalidated and CurrentTimeInvalidated. CurrentStateInvalidated
    will fire whenver the timelines CurrentState property of the timeline's
    clock is updated. CurrentTimeInvalidated fires whenever the CurrentTime
    propery of the timeline's clock is updated. Figuring out exactly what the
    current state of the clock represents can be a little tricky, take a look at
    http://windowssdk.msdn.microsoft.com/en-us/library/system.windows.media.animation.clockstate.aspx.
    It has some good graphics that detail exactly what happens when.


    I've also read that the timeline's clock is directly controllable. So, you
    should be able to set it anywhere in the timeline you want, manually.

    Hope this helps!

    Michael G. Emmons
    http://xamlxaml.com


    "obalu" <obalu@discussions.microsoft.com> wrote in message
    news:ACDB1055-F7C4-4FBA-879E-5D6BCC4CA4B8@microsoft.com...

    Click to show or hide original message or reply text.

    Tuesday, February 19, 2008 6:19 PM
  • By: Brennon Williams
    Howdy Michael,

    I see you have changed your logon name!! Anyway, have you had time to try
    and get this working? It is something I have been meaning to tackle for quite
    awhile but I dont have much dev time available at the moment and just
    wondered if you have had any success?

    To the MS team, will you include keyframe naming and events in release 1?
    It's a pretty important feature, and by the look of it, one the designers
    require.


    Cheers

    "Beta Tester" wrote:

    Click to show or hide original message or reply text.

    Tuesday, February 19, 2008 6:20 PM
  • By: Michael G. Emmons
    Heh, yeah, I was posting from my beta testing computer, thus the name.

    I'll take a look at this later on today and see what I can come up with.

    -MGE

    "Brennon Williams" <BrennonWilliams@discussions.microsoft.com> wrote in
    message news:7766856E-A7E7-4E93-BFB8-C3AB0F3E9F12@microsoft.com...
    > Howdy Michael,
    >
    > I see you have changed your logon name!! Anyway, have you had time to try
    > and get this working? It is something I have been meaning to tackle for
    > quite
    > awhile but I dont have much dev time available at the moment and just
    > wondered if you have had any success?
    >
    > To the MS team, will you include keyframe naming and events in release 1?
    > It's a pretty important feature, and by the look of it, one the designers
    > require.
    >
    >
    > Cheers
    >
    > "Beta Tester" wrote:
    >
    >> The only timeline related event triggers that can be captured are
    >> begin/end/pause/resume. The xaml would look something like:
    >>
    >> <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="Button">
    >> <BeginStoryboard Storyboard="{StaticResource Timeline1}"
    >> x:Name="Timeline1_BeginStoryboard"/>
    >> </EventTrigger>
    >>
    >> In code this would be the equivalent of:
    >>
    >> myButton.Click += delegate(object sender, RoutedEventArgs args)
    >> {
    >> myStoryboard.Begin(myButton);
    >> };
    >>
    >>
    >> If you look at the storyboard class you will see that it has a Completed
    >> event. Presumably this fires whenever the storyboard completes the
    >> animation. Subscribing to this event you could do whatever you need to do
    >> once the animation completes:
    >>
    >> ....
    >> {
    >> ....
    >> Storyboard story = new Storyboard();
    >> story.Completed += new EventHandler(story_Completed);
    >> }
    >>
    >> void story_Completed(object sender, EventArgs e)
    >> {
    >> // Do whatever needs to be done when animation is complete
    >> }
    >>
    >> There is also another couple of interesting event handlers:
    >> CurrentStateInvalidated and CurrentTimeInvalidated.
    >> CurrentStateInvalidated
    >> will fire whenver the timelines CurrentState property of the timeline's
    >> clock is updated. CurrentTimeInvalidated fires whenever the CurrentTime
    >> propery of the timeline's clock is updated. Figuring out exactly what the
    >> current state of the clock represents can be a little tricky, take a look
    >> at
    >>
    http://windowssdk.msdn.microsoft.com/en-us/library/system.windows.media.animation.clockstate.aspx.
    >> It has some good graphics that detail exactly what happens when.
    >>
    >>
    >> I've also read that the timeline's clock is directly controllable. So,
    >> you
    >> should be able to set it anywhere in the timeline you want, manually.
    >>
    >> Hope this helps!
    >>
    >> Michael G. Emmons
    >>
    http://xamlxaml.com
    >>
    >>
    >> "obalu" <obalu@discussions.microsoft.com> wrote in message
    >> news:ACDB1055-F7C4-4FBA-879E-5D6BCC4CA4B8@microsoft.com...
    >> > Hi,
    >> >
    >> > How is it posibble to issue commands form a given Timeline Position?
    >> > E.G I have a page with 4 images, and whichever the user clicks on will
    >> > "grow" untill it reaches full size. This is the point where I would
    >> > like
    >> > to
    >> > switch to another page.
    >> > I know, this problem can be solved with the animation on the new page,
    >> > but
    >> > some other examples could not.
    >> > I've read a word about timeline listeners in another post. What are
    >> > these?
    >> >
    >> > Thanks,
    >> >
    >> > Balint
    >> >
    >>
    >>

    Tuesday, February 19, 2008 6:21 PM
  • By: obula
    Thanks, it helped a lot, but I still can't quite figure it out.
    At a MSDN example
    http://windowssdk.msdn.microsoft.com/en-us/library/ms741973.aspx
    I saw, that in a function he can call myStoryboard.
    But if I try it in my project with Timeline1(which is an existing
    timeleine), E.G
    ..
    Timeline1.Begin();

    I get the error message when compiling:
    "The name 'Timeline1' does not exist in the current context.

    What could be the problem?
    Thanks,

    Balint

    "Beta Tester" wrote:

    Click to show or hide original message or reply text.


    Tuesday, February 19, 2008 6:21 PM
  • By: Michael G. Emmons
    For most XAML objects (that is, objects which are defined in the .xaml file,
    not ones defined in the .xaml.cs file) you need to get a reference to them
    using FindResource. To get a reference to your timeline issue the following:

    Storyboard myStoryBoard = (Storyboard)this.FindResource("Timeline1");



    "obalu" <obalu@discussions.microsoft.com> wrote in message
    news:75C252C4-CD66-40B8-90D1-D7C6B1C7E2E4@microsoft.com...
    > Thanks, it helped a lot, but I still can't quite figure it out.
    > At a MSDN example
    >
    http://windowssdk.msdn.microsoft.com/en-us/library/ms741973.aspx
    > I saw, that in a function he can call myStoryboard.
    > But if I try it in my project with Timeline1(which is an existing
    > timeleine), E.G
    > ..
    > Timeline1.Begin();
    >
    > I get the error message when compiling:
    > "The name 'Timeline1' does not exist in the current context.
    >
    > What could be the problem?
    > Thanks,
    >
    > Balint
    >
    > "Beta Tester" wrote:
    >
    >> The only timeline related event triggers that can be captured are
    >> begin/end/pause/resume. The xaml would look something like:
    >>
    >> <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="Button">
    >> <BeginStoryboard Storyboard="{StaticResource Timeline1}"
    >> x:Name="Timeline1_BeginStoryboard"/>
    >> </EventTrigger>
    >>
    >> In code this would be the equivalent of:
    >>
    >> myButton.Click += delegate(object sender, RoutedEventArgs args)
    >> {
    >> myStoryboard.Begin(myButton);
    >> };
    >>
    >>
    >> If you look at the storyboard class you will see that it has a Completed
    >> event. Presumably this fires whenever the storyboard completes the
    >> animation. Subscribing to this event you could do whatever you need to do
    >> once the animation completes:
    >>
    >> ....
    >> {
    >> ....
    >> Storyboard story = new Storyboard();
    >> story.Completed += new EventHandler(story_Completed);
    >> }
    >>
    >> void story_Completed(object sender, EventArgs e)
    >> {
    >> // Do whatever needs to be done when animation is complete
    >> }
    >>
    >> There is also another couple of interesting event handlers:
    >> CurrentStateInvalidated and CurrentTimeInvalidated.
    >> CurrentStateInvalidated
    >> will fire whenver the timelines CurrentState property of the timeline's
    >> clock is updated. CurrentTimeInvalidated fires whenever the CurrentTime
    >> propery of the timeline's clock is updated. Figuring out exactly what the
    >> current state of the clock represents can be a little tricky, take a look
    >> at
    >>
    http://windowssdk.msdn.microsoft.com/en-us/library/system.windows.media.animation.clockstate.aspx.
    >> It has some good graphics that detail exactly what happens when.
    >>
    >>
    >> I've also read that the timeline's clock is directly controllable. So,
    >> you
    >> should be able to set it anywhere in the timeline you want, manually.
    >>
    >> Hope this helps!
    >>
    >> Michael G. Emmons
    >>
    http://xamlxaml.com
    >>
    >>
    >> "obalu" <obalu@discussions.microsoft.com> wrote in message
    >> news:ACDB1055-F7C4-4FBA-879E-5D6BCC4CA4B8@microsoft.com...
    >> > Hi,
    >> >
    >> > How is it posibble to issue commands form a given Timeline Position?
    >> > E.G I have a page with 4 images, and whichever the user clicks on will
    >> > "grow" untill it reaches full size. This is the point where I would
    >> > like
    >> > to
    >> > switch to another page.
    >> > I know, this problem can be solved with the animation on the new page,
    >> > but
    >> > some other examples could not.
    >> > I've read a word about timeline listeners in another post. What are
    >> > these?
    >> >
    >> > Thanks,
    >> >
    >> > Balint
    >> >
    >>
    >>


    Tuesday, February 19, 2008 6:22 PM