WPF TranslateTransform的使用
1、水平移动
2、单击后向X,Y移动15
<Canvas x:Class="ControlTest2.TranslateTransformDemon.TranslateTransformInCanvas" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="300" Width="300"> <Rectangle MouseLeftButtonDown="Rectangle_MouseLeftButtonDown" Width="50" Height="50" Fill="RoyalBlue"> <Rectangle.RenderTransform> <TranslateTransform x:Name="myTranslateTransform" /> </Rectangle.RenderTransform> </Rectangle> </Canvas>
Code:
private void Rectangle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { // Increase the X and Y properties. myTranslateTransform.X = myTranslateTransform.X + 15; myTranslateTransform.Y = myTranslateTransform.Y + 15; }