How to wait for state changing transition to finish in Silverlight 4?

前端 未结 3 2096
花落未央
花落未央 2021-02-19 18:22

I need to change state of a control and then do some action. To be specific, I want to run an animation before a control is hidden. I would like to do something like that:

3条回答
  •  感动是毒
    2021-02-19 18:55

    It is in fact possible to attach the Completed handler in code:

    Collection grps = (Collection)VisualStateManager.GetVisualStateGroups(this.LayoutRoot);
    foreach (VisualStateGroup grp in grps) {
        Collection states = (Collection)grp.States;
        foreach (VisualState state in states) {
            switch (state.Name) {
                case "Intro":
                state.Storyboard.Completed += new EventHandler(Intro_Completed);break;
            }
        }
    }
    

    Example from this thread: http://forums.silverlight.net/forums/p/38027/276746.aspx

    Working for me in live project using attached Behavior too! Slightly annoying though that I had to use separate dependency properties for the root UserControl (to use in VisualStateManager.GoToState) and the LayoutRoot to get the actual VisualStateGroup collection.

提交回复
热议问题