ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • WPF 2D Scale Transforms
    .NET/WPF 2D 2013. 6. 28. 00:17
    반응형






    <Window x:Class="WpfApplication10.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Scale Transforms" Height="330" Width="480">
    <Window.Resources >
    <SolidColorBrush x:Key="MyGrayGridBrush" Color="YellowGreen"/>
    </Window.Resources>
    <Viewbox Stretch="Uniform">
    <Grid Width="525" Height="330" 
        HorizontalAlignment="Left" 
        VerticalAlignment="Top"  
        ShowGridLines="True">
    <Grid.ColumnDefinitions>
    	<ColumnDefinition Width="260" />
    	<ColumnDefinition Width="260" />
    </Grid.ColumnDefinitions>
     
    <StackPanel Grid.Column="0">
    	<TextBlock HorizontalAlignment="Center" 
                    Margin="10,10,10,0" 
                    TextWrapping="Wrap"  
                    FontSize="14" FontWeight="Bold" 
                    Text="Scaling Animation"/>
    	<TextBlock Margin="10,10,10,0"  
                    TextWrapping="Wrap" 
                    Text="The scaling parameters ScaleX 
                and ScaleY are animated from 0 to 4."/>
    	<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>
    					<ScaleTransform 
                                x:Name="rectScale" 
                                CenterX="25"  
                                CenterY="35" />
    				</Rectangle.RenderTransform>
    			</Rectangle>
     
    			<!-- Animate the rectangle: -->
    			<Canvas.Triggers>
    				<EventTrigger RoutedEvent="Canvas.Loaded">
    					<BeginStoryboard>
    						<Storyboard RepeatBehavior="Forever" 
    							AutoReverse="True">
    						<DoubleAnimation 
    							Storyboard.TargetName="rectScale" 
    							Storyboard.TargetProperty="ScaleX" 
    							From="0" To="4" Duration="0:0:5"/>
    						<DoubleAnimation  
    							Storyboard.TargetName="rectScale" 
    							Storyboard.TargetProperty="ScaleY" 
    							From="0" To="4" 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 Scaling"/>
    	<Grid Width="260" Height="26" 
                HorizontalAlignment="Left" 
                VerticalAlignment="Top">
    		<Grid.ColumnDefinitions>
    			<ColumnDefinition Width="70" />
    			<ColumnDefinition Width="50" />
    			<ColumnDefinition Width="70" />
    			<ColumnDefinition Width="50" />
    		</Grid.ColumnDefinitions>
     
    		<TextBlock Margin="2,2,10,2" 
                        TextAlignment="Right" 
                        Text="ScaleX"/>
    		<Slider Name="tbScaleX" Width="50" 
                        Height="20" Grid.Column="1" 
                        Maximum="10" Minimum="-10" Value="1"/>
    		<TextBlock Margin="2,2,10,2" 
                        Grid.Column="2" 
                        TextAlignment="Right" 
                        Text="ScaleY"/>
    		<Slider Name="tbScaleY" Width="50" 
                        Height="20" Grid.Column="3" 
                        Maximum="10" Minimum="-10" Value="1"/>
    	</Grid>
     
    	<Border Margin="10" BorderBrush="Black" 
                BorderThickness="1" 
            Background="{StaticResource MyGrayGridBrush}" 
                HorizontalAlignment="Left">
    		<Canvas ClipToBounds="True"  
                    Width="240" 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>
    					<ScaleTransform  
    		ScaleX="{Binding ElementName=tbScaleX,Path=Value}" 
    		ScaleY="{Binding ElementName=tbScaleY,Path=Value}" 
    			CenterX="25" CenterY="35"/>
    				</Rectangle.RenderTransform>
    			</Rectangle>
    		</Canvas>
    	</Border>
    </StackPanel>
    </Grid>
    </Viewbox>
    </Window>






    reference : Practical WPF Graphics Programming









    반응형

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

    WPF 2D Composite Transforms  (0) 2013.07.04
    WPF 2D SkewTransform  (0) 2013.07.04
    WPF 2D RotateTransform  (0) 2013.07.04
    WPF 2D TranslateTransform  (0) 2013.07.03
    WPF 2D Object Matrix Transforms  (0) 2013.06.28
    WPF 2D Creating Perpendicular Lines  (0) 2013.06.27
    WPF 2D Transformations Matrix Transforms  (0) 2013.06.27
    WPF Basic 2D Graphics Shapes  (0) 2013.06.19

    댓글

Designed by Tistory.