私が提案するXAMLを使用してグループ自体を作成する必要があります。次に、探しているVisualStateGroupを次のように見つける必要があります。
VisualStateGroup visualStateGroupLookingFor = null;
var visualStateGroups = (VisualStateManager.GetVisualStateGroups(LayoutRoot));
foreach (VisualStateGroup state in visualStateGroups) {
if (state.Name == "VisualStateGroupMine") {
visualStateGroupLookingFor = state;
break;
}
}
次に、追加する新しい VisualState と Storyboard を作成する必要があります。次に例を示します。
var visualState = new VisualState();
var storyBoard = new Storyboard();
次に、アニメーションを作成します。
var animation = new DoubleAnimation();
animation.To = 10.0;
そして、アニメーションのターゲットを設定します:
//assuming this is instance of class ClassFoo
//and you want to animate it's Width
Storyboard.SetTarget(animation, this);
Storyboard.SetTargetProperty(animation, new PropertyPath(ClassFoo.WidthProperty));
最後に、アニメーションをストーリーボードに追加し、名前を付けて、visualstategroup に追加します。
storyBoard.Children.Add(animation);
visualState.Storyboard = storyBoard;
visualState.Name = "CoolNameLikeWidthAnimation";
visualStateGroupLookingFor.States.Add(visualState);
それだけです。いつものようにトリガーします
VisualStateManager.GoToState(this, "CoolNameLikeWidthAnimation", true);