I am practicing on visual States, so defined custom visual state group which has its own visual states.
C# Code:
//This Represents the Group of Custom Visual State to which we add number of visual states
VisualStateGroup MyVisualStateGroup = new VisualStateGroup();
//This Represents Custom Visual State to which we apply storyboard
VisualState FirstVisualState = new VisualState();
//This Represents the Storyboard which we add number of double animations
Storyboard MyStoryBoard = new Storyboard();
//This Represents the Double Animation
DoubleAnimation FirstDoubleAnimation = new DoubleAnimation();
//Defining Animation Attributes
FirstDoubleAnimation.To = 0;
FirstDoubleAnimation.BeginTime = TimeSpan.Zero;
FirstDoubleAnimation.Duration = TimeSpan.Parse("00:00:00.50");
//Specifying which property to animate
Storyboard.SetTargetProperty(FirstDoubleAnimation , new PropertyPath("(FrameworkElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)"));
//This Represents the Double Animation
DoubleAnimation SecondDoubleAnimation = new DoubleAnimation();
//Defining Animation Attributes
SecondDoubleAnimation.To = -500;
SecondDoubleAnimation.BeginTime = TimeSpan.Zero;
SecondDoubleAnimation.Duration = TimeSpan.Parse("00:00:00.50");
//Specifying which property to animate
Storyboard.SetTargetProperty(SecondDoubleAnimation, new PropertyPath("(FrameworkElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)"));
//Setting up target Object(Here it is panel) for particular Double Animation
Storyboard.SetTarget(FirstDoubleAnimation, SecondPanel);
Storyboard.SetTarget(SecondDoubleAnimation, FirstPanel);
//Adding Double Animation to story board
MyStoryBoard.Children.Add(FirstDoubleAnimation);
MyStoryBoard.Children.Add(SecondDoubleAnimation);
//If we don’t want to use custom visual state then here I can story board .
// MyStoryBoard.Begin();
//Applying Story Board to Visual State
FirstVisualState.Storyboard = MyStoryBoard;
String VisualStateName = "MyState";
//Giving name(by which it is called) to Visual State
FirstVisualState.SetValue(NameProperty, VisualStateName);
//Retireving visual state name
//string VisualStateName = FirstVisualState.Name;
//We can have more then visual state for particular UIElment \ FrameElement \ Usercontrol
//Here we are making collection of visual states
System.Collections.ObjectModel.Collection
MyStates.Add(FirstVisualState);
//This Represents the Visual Transition
VisualTransition MyVisualTransition = new VisualTransition();
MyVisualTransition.Duration = TimeSpan.Parse("00:00:00.50");
//Here we are making collection of visual transitions
System.Collections.ObjectModel.Collection
MyTrans.Add(MyVisualTransition);
//Here we are binding visual states and visual transitions to the visual state group
MyVisualStateGroup.States = MyStates;
MyVisualStateGroup.Transitions = MyTrans;
//we can have multiple visual state groups also.
//Then we can particular visual state by the help visual state manage for example:-
// VisualStateManager.GoToState(this, " FirstVisualState ", true);
Now here is one problem........
In above c# code we didn’t attach visual state group to the page. I am not able to do so.
Any help in this regard will be highly appreciated.
Any comments and feedbacks regarding this code welcomed.