<Window x:Class="WpfApplication12.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="RotateTransform" Height="330" Width="710"> <Window.Resources > <SolidColorBrush x:Key="MyGrayGridBrush" Color="YellowGreen"/> </Window.Resources> <Viewbox Stretch="Uniform"> <Grid Width="725" Height="330" HorizontalAlignment="Left" VerticalAlignment="Top" ShowGridLines="True"> <Grid.ColumnDefinitions> <ColumnDefinition Width="310" /> <ColumnDefinition Width="410" /> </Grid.ColumnDefinitions> <StackPanel Grid.Column="0"> <TextBlock HorizontalAlignment="Center" Margin="10,10,10,0" TextWrapping="Wrap" FontSize="14" FontWeight="Bold" Text="Rotation Animation"/> <TextBlock Margin="10,10,10,0" TextWrapping="Wrap" Text="The Rotation properties is animated from 0 to 360, and the center property is animated form (-20,-50) to (120,90) "/> <Border Margin="10" BorderBrush="Black" BorderThickness="1" Background="{StaticResource MyGrayGridBrush}" HorizontalAlignment="Left"> <Canvas ClipToBounds="True" Width="240" Height="250"> <Rectangle Canvas.Left="100" Canvas.Top="80" Width="50" Height="70" Fill="LightCoral" Opacity="0.5" Stroke="Black" StrokeThickness="2"> <Rectangle.RenderTransform> <RotateTransform x:Name="rotate"/> </Rectangle.RenderTransform> </Rectangle> <!-- Animate the rectangle: --> <Canvas.Triggers> <EventTrigger RoutedEvent="Canvas.Loaded"> <BeginStoryboard> <Storyboard RepeatBehavior="Forever"> <DoubleAnimation Storyboard.TargetName="rotate" Storyboard.TargetProperty="Angle" From="0" To="360" Duration="0:0:5"/> <DoubleAnimation Storyboard.TargetName="rotate" Storyboard.TargetProperty="CenterX" From="-20" To="120" Duration="0:0:5"/> <DoubleAnimation Storyboard.TargetName="rotate" Storyboard.TargetProperty="CenterY" From="-50" To="90" Duration="0:0:5"/> </Storyboard> </BeginStoryboard> </EventTrigger> </Canvas.Triggers> </Canvas> </Border> </StackPanel> <StackPanel Grid.Column="1"> <TextBlock HorizontalAlignment="Center" Margin="10,10,10,10" TextWrapping="Wrap" FontSize="14" FontWeight="Bold" Text="Interactive Rotation"/> <Grid Width="360" Height="26" HorizontalAlignment="Left" VerticalAlignment="Top"> <Grid.ColumnDefinitions> <ColumnDefinition Width="70" /> <ColumnDefinition Width="50" /> <ColumnDefinition Width="70" /> <ColumnDefinition Width="50" /> <ColumnDefinition Width="70" /> <ColumnDefinition Width="50" /> </Grid.ColumnDefinitions> <TextBlock Margin="2,2,10,2" TextAlignment="Right" Text="CenterX"/> <Slider Name="tbCenterX" Width="50" Height="20" Grid.Column="1" Maximum="300" Minimum="-300" Value="0"/> <TextBlock Margin="2,2,10,2" Grid.Column="2" TextAlignment="Right" Text="CenterY"/> <Slider Name="tbCenterY" Width="50" Height="20" Grid.Column="3" Maximum="300" Minimum="-300" Value="0"/> <TextBlock Margin="2,2,10,2" Grid.Column="4" TextAlignment="Right" Text="angle"/> <Slider Name="tbAngle" Width="50" Height="20" Grid.Column="5" Maximum="360" Minimum="0" Value="0"/> </Grid> <Border Margin="10" BorderBrush="Black" BorderThickness="1" Background="{StaticResource MyGrayGridBrush}" HorizontalAlignment="Left"> <Canvas ClipToBounds="True" Width="410" Height="250"> <TextBlock Canvas.Left="90" Canvas.Top="63" Text="Original shape"/> <Rectangle Canvas.Top="80" Canvas.Left="100" Width="50" Height="70" Stroke="Black" StrokeThickness="1" StrokeDashArray="3,1"/> <Rectangle Canvas.Top="80" Canvas.Left="100" Width="50" Height="70" Fill="LightCoral" Opacity="0.5" Stroke="Black" StrokeThickness="2"> <!-- Set interactive scale: --> <Rectangle.RenderTransform> <RotateTransform CenterX="{Binding ElementName=tbCenterX,Path=Value}" CenterY="{Binding ElementName=tbCenterY,Path=Value}" Angle="{Binding ElementName=tbAngle,Path=Value}" /> </Rectangle.RenderTransform> </Rectangle> </Canvas> </Border> </StackPanel> </Grid> </Viewbox> </Window>
reference : Practical WPF Graphics Programming
'.NET > WPF 2D' 카테고리의 다른 글
WPF 2D Geometry Group (0) | 2013.07.11 |
---|---|
WPF Geometry and 2D Drawing (0) | 2013.07.11 |
WPF 2D Composite Transforms (0) | 2013.07.04 |
WPF 2D SkewTransform (0) | 2013.07.04 |
WPF 2D TranslateTransform (0) | 2013.07.03 |
WPF 2D Scale Transforms (0) | 2013.06.28 |
WPF 2D Object Matrix Transforms (0) | 2013.06.28 |
WPF 2D Creating Perpendicular Lines (0) | 2013.06.27 |