본문 바로가기

.NET/WPF 2D

WPF 2D Composite Transforms

반응형










<Window x:Class="WpfApplication14.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
Title="Combining Transforms" Height="330" Width="300">
<Window.Resources >
<SolidColorBrush x:Key="MyGrayGridBrush" Color="YellowGreen"/>
</Window.Resources>
<Viewbox Stretch="Uniform">
<StackPanel>
<TextBlock HorizontalAlignment="Center" 
        Margin="10,10,10,0" TextWrapping="Wrap" 
        FontSize="14" FontWeight="Bold" 
    Text="Animation of Combining Transform"/>
<Border Margin="10" BorderBrush="Black" 
    BorderThickness="1" 
    Background="{StaticResource MyGrayGridBrush}" 
    HorizontalAlignment="Left">
<Canvas ClipToBounds="True"  
        Width="340" Height="320">
	<Ellipse Canvas.Left="165" 
                Canvas.Top="145" Width="10"  
                Height="10" Fill="Red"/>
 
	<Rectangle Canvas.Left="120" 
                Canvas.Top="100" Width="100"  
                Height="100" Fill="LightCoral" 
                Opacity="0.5" Stroke="Black" 
                StrokeThickness="2">
		<Rectangle.RenderTransform>
			<TransformGroup>
				<ScaleTransform x:Name="scale" 
                                CenterX="50" 
                                CenterY="50" />
				<RotateTransform 
                    x:Name="rotate" 
                    CenterX="50" 
                    CenterY="50"/>
			</TransformGroup>
		</Rectangle.RenderTransform>
	</Rectangle>
 
	<!-- Animate the shape: -->
	<Canvas.Triggers>
		<EventTrigger RoutedEvent="Canvas.Loaded">
			<BeginStoryboard>
				<Storyboard RepeatBehavior="Forever"  
            AutoReverse="True">
					<DoubleAnimation Storyboard.TargetName="scale" 
            Storyboard.TargetProperty="ScaleX" 
            From="0" To="3" Duration="0:0:5"/>
					<DoubleAnimation Storyboard.TargetName="scale" 
            Storyboard.TargetProperty="ScaleY" 
            From="0" To="3" Duration="0:0:5"/>
					<DoubleAnimation Storyboard.TargetName="rotate" 
            Storyboard.TargetProperty="Angle" 
            From="0" To="360" Duration="0:0:5"/>
				</Storyboard>
			</BeginStoryboard>
		</EventTrigger>
	</Canvas.Triggers>
</Canvas>
</Border>
</StackPanel>
</Viewbox>
</Window>   




TransformGroup tg = new TransformGroup(); 

tg.Children.Add(ScaleTransform(2, 3)); 

tg.Children.Add(TranslateTransform(100, -100)); 

tg.Children.Add(RotateTransform(45)); 

tg.Children.Add(SkewTransform(30, 45)); 

Rectangle.RenderTransform = tg; 



reference : Practical WPF Graphics Programming








'.NET > WPF 2D' 카테고리의 다른 글

WPF 2D PathGeometry Class  (0) 2013.07.11
WPF 2D Combined Geometry  (0) 2013.07.11
WPF 2D Geometry Group  (0) 2013.07.11
WPF Geometry and 2D Drawing  (0) 2013.07.11
WPF 2D SkewTransform  (0) 2013.07.04
WPF 2D RotateTransform  (0) 2013.07.04
WPF 2D TranslateTransform  (0) 2013.07.03
WPF 2D Scale Transforms  (0) 2013.06.28