You should create the Group itself using XAML I suggest, then
you have to find the VisualStateGroup you are Looking for like this:
VisualStateGroup visualStateGroupLookingFor = null;
var visualStateGroups = (VisualStateManager.GetVisualStateGroups(LayoutRoot));
foreach (VisualStateGroup state in visualStateGroups) {
if (state.Name == "VisualStateGroupMine") {
visualStateGroupLookingFor = state;
break;
}
}
Then, you have to create a new VisualState and Storyboard to add, for example:
var visualState = new VisualState();
var storyBoard = new Storyboard();
Now, create the animation:
var animation = new DoubleAnimation();
animation.To = 10.0;
And set the target of the animation:
//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));
Finally add the animation(s) to your storyboard, give it a name, add it to the visualstategroup:
storyBoard.Children.Add(animation);
visualState.Storyboard = storyBoard;
visualState.Name = "CoolNameLikeWidthAnimation";
visualStateGroupLookingFor.States.Add(visualState);
Thats it, trigger it as usual with
VisualStateManager.GoToState(this, "CoolNameLikeWidthAnimation", true);