ScaleTransform 类
命名空间: System.Windows.Media
程序集: PresentationCore.dll
使用 ScaleTransform 可以水平或垂直拉伸或收缩对象。 ScaleX属性指定沿 x 轴拉伸或收缩对象的程度,而 ScaleY 属性指定沿 y 轴拉伸或收缩对象的量量。 缩放操作以和属性指定的点为中心 CenterX CenterY 。
public void ScanAnimaction(object sender, MouseButtonEventArgs e)
{
Dispatcher.Invoke(() => {
TextBlock textBlock = (TextBlock)sender;
TransformGroup transformGroup = new TransformGroup();
ScaleTransform scaleTransform = new ScaleTransform();
transformGroup.Children.Add(scaleTransform);
DoubleAnimation animation = new DoubleAnimation
{
From = 1,
To = 0.9,
Duration = TimeSpan.FromSeconds(0.30),
FillBehavior = FillBehavior.Stop
};
textBlock.RenderTransform = transformGroup;
scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, animation);
scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, animation);
});
}
可用于实现点击时的动画效果
完整代码如下:
private void Border_Click(object sender, MouseButtonEventArgs e)
{
//点击按键
Border border = sender as Border;
Type type = border.Child.GetType();
if (type.Name.Equals("TextBlock"))
{
TextBlock textBlock = border.Child as TextBlock;
if (textBlock.Text.Equals("清 空"))
{
PassWord = Chongze.Const.HotelConst.EMPTY;
txtPassword.Text = Chongze.Const.HotelConst.EMPTY;
}
else if (txtPassword.Text.Length < 6)
{
new Thread(() => { ScanAnimaction(textBlock, e); }).Start();
PassWord += textBlock.Text;
if (UserName != Chongze.Const.HotelConst.EMPTY)
{
txtPassword.Text += "*";
}
else
{
txtPassword.Text += textBlock.Text;
}
txtPassword.SelectionStart = txtPassword.Text.Length;
}
}
else
{
if (txtPassword.Text.Length > 0)
{
PassWord = PassWord.Remove(txtPassword.Text.Length - 1, 1);
txtPassword.Text = txtPassword.Text.Remove(txtPassword.Text.Length - 1, 1);
}
txtPassword.SelectionStart = txtPassword.Text.Length;
}
}
//输入动画
public void ScanAnimaction(object sender, MouseButtonEventArgs e)
{
Dispatcher.Invoke(() => {
TextBlock textBlock = (TextBlock)sender;
TransformGroup transformGroup = new TransformGroup();
ScaleTransform scaleTransform = new ScaleTransform();
transformGroup.Children.Add(scaleTransform);
DoubleAnimation animation = new DoubleAnimation
{
From = 1,
To = 0.9,
Duration = TimeSpan.FromSeconds(0.30),
FillBehavior = FillBehavior.Stop
};
textBlock.RenderTransform = transformGroup;
scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, animation);
scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, animation);
});
}