Skip to main content
Home Forums Silverlight Programming Programming with .NET - General VisualStateManager question: where is the complete event?
5 replies. Latest Post by greenbob16 on February 24, 2009.
(0)
codism
Member
372 points
121 Posts
06-10-2008 2:09 PM |
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
Participant
1084 points
249 Posts
06-11-2008 12:35 AM |
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.
06-11-2008 9:33 AM |
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.
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.
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 L...
All-Star
25052 points
2,747 Posts
06-12-2008 2:26 AM |
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)
06-12-2008 7:42 AM |
Yi-Lun Luo - MSFT:The Visual States are defined under the root Panel tag, not the UserControl tag.
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
5 points
12 Posts
02-24-2009 11:38 AM |
Does the last solution work? It doesn't work for me. I receive an empty collection whenever I call: VisualStateManager.GetVisualStateGroups(LayoutRoot);