== WPF Control Transforms and Animations ==
== Transforms ==
XAML:
Programmatically in C#:
// Create transform group, then add transform operations to it.
// Finally, add transform group to the control.
TransformGroup TFG = new TransformGroup();
SkewTransform skewTransform1 = new SkewTransform(0, -20, 0, 0);
TranslateTransform transTransform1 = new TranslateTransform(-90, 0);
TFG.Children.Add(transTransform1);
TFG.Children.Add(skewTransform1);
btnProducts.RenderTransform = TFG;
Flip an image horizontally (on Y axis). XAML:
Flip an image horizontally (on Y axis). C#:
// Scale Transform: Flip image on Y axis
ScaleTransform scaletrans = new ScaleTransform();
scaletrans.ScaleX = -1;
imgProduct.LayoutTransform = scaletrans;
// Translate Transform: Move image 100 pixels (X axis)
TranslateTransform tt = new TranslateTransform(100, 0);
imgProduct.RenderTransform = tt;
=== References ===
* [[http://dotnetwizard.net/coding/pan-zoom-rotate-images-with-wpf-using-c/|Pan, Zoom, Rotate images with WPF using C#]]
== Animations ==
// Add Animation for btnSearch
DoubleAnimation anim = new DoubleAnimation();
anim.From = 90;
anim.To = 120;
anim.AutoReverse = true;
anim.AccelerationRatio = .33;
anim.DecelerationRatio = .33;
btnSearch.BeginAnimation(Button.WidthProperty, anim);
**Other Examples**
XAML:
C#:
private void btnAnimate_Click(object sender, RoutedEventArgs e)
{
AnimateEllipse();
AnimateTriangle();
}
private void AnimateEllipse()
{
TranslateTransform tt = new TranslateTransform(0, 0);
DoubleAnimation daX = new DoubleAnimation(100,
new Duration(TimeSpan.FromMilliseconds(500))
);
DoubleAnimation daY = new DoubleAnimation(50,
new Duration(TimeSpan.FromMilliseconds(500))
);
tt.BeginAnimation(TranslateTransform.XProperty, daX);
tt.BeginAnimation(TranslateTransform.YProperty, daY);
shapeEllipse.RenderTransform = tt;
}
private void AnimateTriangle()
{
// Scale Transform
ScaleTransform scaletrans = new ScaleTransform();
scaletrans.ScaleX = -1;
//scaletrans.CenterX = 0.25;
shapeTriangle.LayoutTransform = scaletrans;
// Translate Transform
TranslateTransform tt = new TranslateTransform(100, 0);
shapeTriangle.RenderTransform = tt;
}
=== References ===
* [[http://www.galasoft.ch/mydotnet/articles/article-2006102701.aspx|WPF: Animations in XAML and code behind]]
== Control Triggering Animation of Another Control ==
''Button'' click triggers ''Border'' animation.
Here is the button definition:
Border that gets animated:
...