Silverlight图形学习笔记(三):变换

<UserControl x:Class="GeometryStudy.MainPage"
xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d
="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc
="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable
="d"
d:DesignHeight
="300" d:DesignWidth="400" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
<!--
(一)(1)Silverlight 中使用二维 (2-D) Transform 类来旋转、按比例缩放、扭曲和移动(平移)对象
(2)Transform定义如何将一个坐标空间中的点映射或变换到另一个坐标空间。此映射由变换 Matrix(一个三行三列的 Double 值集合)
(二)变换的分类:
简单变换:
(1)RotateTransform变换:按指定的 Angle 旋转元素
(2)ScaleTransform变换:按指定的 ScaleX 和 ScaleY 量按比例缩放元素
(3)SkewTransform变换:按指定的 AngleX 和 AngleY 量扭曲元素。
(4)TranslateTransform:按指定的 X 和 Y 量移动(平移)元素。
复杂变换:
(1)CompositeTransform:使用此类对同一对象应用多个变换(如扭曲和旋转)。此类以首选顺序应用多个变换
(2)TransformGroup :与CompositeTransform类似,但以特定顺序应用变换,或者希望为不同变换应用不同的中心点
(3)MatrixTransform :提供的自定义变换,直接处理矩阵
(三)常见变换属性
(1)Brush类可以进行 Transform ,RelativeTransform变换
(2)Geometry 可以Transform
(3)UIElement可以RenderTransform
-->

<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>

<StackPanel Grid.Row="0">
<!--以顶点作为旋转点旋转45度-->
<Rectangle Width="50" Height="50" Fill="RoyalBlue" Margin="0,0,0,20">
<Rectangle.RenderTransform>
<RotateTransform Angle="45" />
</Rectangle.RenderTransform>
</Rectangle>
<!--正方形中心作为旋转点旋转45度-->
<Rectangle Width="50" Height="50" Fill="RoyalBlue">
<Rectangle.RenderTransform>
<RotateTransform Angle="45" CenterX="25" CenterY="25" />
</Rectangle.RenderTransform>
</Rectangle>
</StackPanel>
<!--旋转动画-->
<StackPanel Grid.Row="1" >
<StackPanel.Resources>
<Storyboard x:Name="myStoryboard">
<DoubleAnimation
Storyboard.TargetName="myTransform"
Storyboard.TargetProperty
="Angle"
From
="0" To="360" Duration="0:0:5"
RepeatBehavior
="Forever"
/>
</Storyboard>
</StackPanel.Resources>
<Rectangle Width="50" Height="50" Fill="RoyalBlue" MouseLeftButtonDown="StartAnimation">
<Rectangle.RenderTransform>
<RotateTransform x:Name="myTransform" Angle="45" CenterX="25" CenterY="25" />
</Rectangle.RenderTransform>
</Rectangle>
</StackPanel>
</Grid>
</UserControl>
posted @ 2011-05-26 00:01  焦涛  阅读(425)  评论(0)    收藏  举报