Skip to main content

Microsoft Silverlight

Answered Question VisualStateManager question: where is the complete event?RSS Feed

(0)

codism
codism

Member

Member

372 points

121 Posts

VisualStateManager question: where is the complete event?

Ok, I finally get used with the expression + vs 2008 for animation. (Thanks caperaven! http://silverlight.net/forums/p/17571/59182.aspx#59182) Now I am trying to find a way to hide some controls after they fade out. I tried to find a storyboard object from where I can wire up a complete event but stuck at the first step: I used the following code in my control's constructor after the InitializeComponents():

            Collection<VisualStateGroup> vsgs = VisualStateManager.GetVisualStateGroups(this);
            foreach (var vsg in vsgs)
            {
                if (vsg.Name == "common_states")
                {
                    foreach (var vs in vsg.States)
                    {
                        if (vs.Name == "mouse_out")
                        {
                            vs.Storyboard.Completed += new EventHandler(Storyboard_Completed);
                            break;
                        }
                    }
                    break;
                }
            }

I got the above logic by looking at the generated xaml code in expression but not sure if it will give me the right storyboard. The problem I am having with the above code is vsgs.Count is always zero. Is there anything I missed or I am on a wrong way?

Thanks in advance! 

Dave Relyea
Dave Relyea

Participant

Participant

1084 points

249 Posts

Microsoft
Answered Question

Re: VisualStateManager question: where is the complete event?

You are right, what you have will no longer work. You could try getting the VisualStateGroups attached property, but that seems like a lot of work.

You can also put your Storyboards in the Resources and access them as StaticResources in your control. Then they'd be easier to find, but it would be a fragile solution and would be hard to re-template.

If you are not worried about re-templating, you know exactly how long the transitions will take so you could start a timer after you call GoToState and hide the control on the tick. You could also simply have a state that you go to that has the control set its visibility to collapsed. That may be the easiest thing to do.

codism
codism

Member

Member

372 points

121 Posts

Answered Question

Re: VisualStateManager question: where is the complete event?

Dave Relyea:

You could also simply have a state that you go to that has the control set its visibility to collapsed. That may be the easiest thing to do.

 

Changing the visibility is just a simplified scenario, more logics have to be performed after a certain animation in my application. That's why I want to have a complete event.

Dave Relyea:

You could try getting the VisualStateGroups attached property, but that seems like a lot of work.

Do you have any idea why GetVisualStateGroups(this) does not work?

Thanks 

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Answered Question

Re: VisualStateManager question: where is the complete event?

Hello, actually this should be able to work. But you should pass the root Panel instead of this (the instance of UserControl) to GetVisualStateGroups. The Visual States are defined under the root Panel tag, not the UserControl tag.

VisualStateManager.GetVisualStateGroups(LayoutRoot)

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

codism
codism

Member

Member

372 points

121 Posts

Answered Question

Re: VisualStateManager question: where is the complete event?

 

Yi-Lun Luo - MSFT:

The Visual States are defined under the root Panel tag, not the UserControl tag.

Oh, you are right! Thanks for pointing it out! Will try it out later today.

--- edited ---

Just tried with the root layout and it works! Thanks again! 

greenbob16
greenbob16

Member

Member

5 points

12 Posts

Re: Re: VisualStateManager question: where is the complete event?

Does the last solution work? It doesn't work for me. I receive an empty collection whenever I call: VisualStateManager.GetVisualStateGroups(LayoutRoot);

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities