첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
본 블로그는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 블로그 콘텐츠 향상을 위해 쓰여집니다.

728x90
반응형
728x170

TestProject.zip
다운로드

▶ MainWindow.xaml

<Window x:Class="TestProject.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="800"
    Height="600"
    Title="RotateTransform 클래스 사용하기"
    FontFamily="나눔고딕코딩"
    FontSize="12">
    <Window.Resources>
        <Style TargetType="{x:Type TextBlock}">
            <Setter Property="Padding"    Value="5"    />
            <Setter Property="FontWeight" Value="Bold" />
        </Style>
        <DrawingBrush x:Key="BlueGridDrawingBrushKey"
            ViewportUnits="Absolute"
            Viewport="0 0 10 10"
            TileMode="Tile">
            <DrawingBrush.Drawing>
                <DrawingGroup>
                    <DrawingGroup.Children>
                        <GeometryDrawing Brush="White">
                            <GeometryDrawing.Geometry>
                                <RectangleGeometry Rect="0 0 1 1" />
                            </GeometryDrawing.Geometry>
                        </GeometryDrawing>
                        <GeometryDrawing
                            Geometry="M 0 0 L 1 0 1 0.1 0 0.1 Z"
                            Brush="#ccccff" />
                        <GeometryDrawing
                            Geometry="M 0 0 L 0 1 0.1 1 0.1 0 Z"
                            Brush="#ccccff" />
                    </DrawingGroup.Children>
                </DrawingGroup>
            </DrawingBrush.Drawing>
        </DrawingBrush>
    </Window.Resources>
    <Border
        Margin="10"
        BorderThickness="1"
        BorderBrush="Black">
        <ScrollViewer>
            <WrapPanel Margin="10">
                <Border
                    HorizontalAlignment="Left"
                    Margin="10"
                    BorderThickness="1"
                    BorderBrush="Black"
                    Background="{StaticResource BlueGridDrawingBrushKey}">
                    <Canvas
                        Width="200"
                        Height="200">
                        <TextBlock>
                            회전 미적용
                        </TextBlock>
                        <Polyline Canvas.Left="75" Canvas.Top="50"
                            StrokeThickness="10"
                            Stroke="Blue"
                            Points="25 25 0 50 25 75 50 50 25 25 25 0" />
                    </Canvas>
                </Border>
                <Border
                    HorizontalAlignment="Left"
                    Margin="10"
                    BorderThickness="1"
                    BorderBrush="Black"
                    Background="{StaticResource BlueGridDrawingBrushKey}">
                    <Canvas
                        Width="200"
                        Height="200">
                        <TextBlock>
                            중심 : 25, 50<LineBreak/>
                            각도 : 45
                        </TextBlock>
                        <Polyline Canvas.Left="75" Canvas.Top="50"
                            Points="25 25 0 50 25 75 50 50 25 25 25 0"
                            Stroke="Blue"
                            StrokeThickness="10"
                            Opacity="0.25" />           
                        <Polyline Canvas.Left="75" Canvas.Top="50"
                            StrokeThickness="10"
                            Stroke="Blue"
                            Points="25 25 0 50 25 75 50 50 25 25 25 0">
                            <Polyline.RenderTransform>
                                <RotateTransform
                                    CenterX="25"
                                    CenterY="50"
                                    Angle="45" />
                            </Polyline.RenderTransform>
                        </Polyline>
                        <Ellipse Canvas.Left="95" Canvas.Top="95"
                            Width="10"
                            Height="10"
                            Fill="Red" />
                    </Canvas>
                </Border>
                <Border
                    HorizontalAlignment="Left"
                    Margin="10"
                    BorderThickness="1"
                    BorderBrush="Black"
                    Background="{StaticResource BlueGridDrawingBrushKey}">
                    <Canvas
                        Width="200"
                        Height="200">
                        <TextBlock>
                            중심 : 0, 0<LineBreak/>
                            각도 : 45
                        </TextBlock>
                        <Polyline Canvas.Left="75" Canvas.Top="50"
                            Points="25 25 0 50 25 75 50 50 25 25 25 0"
                            Stroke="Blue"
                            StrokeThickness="10"
                            Opacity="0.25" />           
                        <Polyline Canvas.Left="75" Canvas.Top="50"
                            StrokeThickness="10"
                            Stroke="Blue"
                            Points="25 25 0 50 25 75 50 50 25 25 25 0">
                            <Polyline.RenderTransform>
                                <RotateTransform
                                    CenterX="0"
                                    CenterY="0"
                                    Angle="45" />
                            </Polyline.RenderTransform>
                        </Polyline>
                        <Ellipse Canvas.Left="70" Canvas.Top="45"
                            Width="10"
                            Height="10"
                            Fill="Red" />
                    </Canvas>
                </Border>
                <Border
                    HorizontalAlignment="Left"
                    Margin="10"
                    BorderThickness="1"
                    BorderBrush="Black"
                    Background="{StaticResource BlueGridDrawingBrushKey}">
                    <Canvas Height="200" Width="200">
                        <TextBlock>
                            중심 : 50%, 50%<LineBreak/>
                            각도 : 45
                        </TextBlock>
                        <Polyline Canvas.Left="75" Canvas.Top="50"
                            StrokeThickness="10"
                            Stroke="Blue"
                            Opacity="0.25"
                            Points="25 25 0 50 25 75 50 50 25 25 25 0" />
                        <Polyline Canvas.Left="75" Canvas.Top="50"
                            StrokeThickness="10"
                            Stroke="Blue"
                            Points="25 25 0 50 25 75 50 50 25 25 25 0"
                            RenderTransformOrigin="0.5 0.5">
                            <Polyline.RenderTransform>
                                <RotateTransform Angle="45" />
                            </Polyline.RenderTransform>
                        </Polyline>
                        <Ellipse Canvas.Left="95" Canvas.Top="82.5"
                            Width="10"
                            Height="10"
                            Fill="Red" />
                    </Canvas>
                </Border>
                <Border
                    HorizontalAlignment="Left"
                    Margin="10"
                    BorderThickness="1"
                    BorderBrush="Black"
                    Background="{StaticResource BlueGridDrawingBrushKey}">
                    <Canvas Height="200" Width="200">
                        <TextBlock>
                            중심 : 25%, 25%<LineBreak/>
                            각도 : 45
                        </TextBlock>
                        <Polyline Canvas.Left="75" Canvas.Top="50"
                            StrokeThickness="10"
                            Stroke="Blue"
                            Opacity="0.25"
                            Points="25 25 0 50 25 75 50 50 25 25 25 0" />
                        <Polyline Canvas.Left="75" Canvas.Top="50"
                            StrokeThickness="10"
                            Stroke="Blue"
                            Points="25 25 0 50 25 75 50 50 25 25 25 0"
                            RenderTransformOrigin="0.25 0.25">
                            <Polyline.RenderTransform>
                                <RotateTransform Angle="45" />
                            </Polyline.RenderTransform>
                        </Polyline>
                        <Ellipse Canvas.Left="82.5" Canvas.Top="63.75"
                            Width="10"
                            Height="10"
                            Fill="Red" />
                    </Canvas>
                </Border>
                <Border
                    HorizontalAlignment="Left"
                    Margin="10"
                    BorderThickness="1"
                    BorderBrush="Black"
                    Background="{StaticResource BlueGridDrawingBrushKey}">
                    <Canvas Height="200" Width="200">
                        <TextBlock>
                            중심 : 25, 50<LineBreak/>
                            각도 : 애니메이션
                        </TextBlock>
                        <Polyline Canvas.Left="75" Canvas.Top="50"
                            StrokeThickness="10"
                            Stroke="Blue"
                            Opacity="0.25"
                            Points="25 25 0 50 25 75 50 50 25 25 25 0" />
                        <Polyline Canvas.Left="75" Canvas.Top="50"
                            StrokeThickness="10"
                            Stroke="Blue"
                            Points="25 25 0 50 25 75 50 50 25 25 25 0">
                            <Polyline.RenderTransform>
                                <RotateTransform x:Name="rotateTransform1"
                                    CenterX="25"
                                    CenterY="50"
                                    Angle="0" />
                            </Polyline.RenderTransform>
                        </Polyline>
                        <Ellipse Canvas.Left="95" Canvas.Top="95"
                            Width="10"
                            Height="10"
                            Fill="Red" />
                    </Canvas>
                </Border>
                <Border
                    HorizontalAlignment="Left"
                    Margin="10"
                    BorderBrush="Black"
                    BorderThickness="1"
                    Background="{StaticResource BlueGridDrawingBrushKey}">
                    <Canvas Height="200" Width="200">
                        <TextBlock>
                            중심 : 애니메이션<LineBreak/>
                            각도 : 애니메이션
                        </TextBlock>
                        <Polyline Canvas.Left="75" Canvas.Top="50"
                            StrokeThickness="10"
                            Stroke="Blue"
                            Opacity="0.25"
                            Points="25 25 0 50 25 75 50 50 25 25 25 0" />
                        <Polyline Canvas.Left="75" Canvas.Top="50"
                            Points="25 25 0 50 25 75 50 50 25 25 25 0"
                            Stroke="Blue"
                            StrokeThickness="10">
                            <Polyline.RenderTransform>
                                <RotateTransform x:Name="rotateTransform2"
                                    CenterX="0"
                                    CenterY="0"
                                    Angle="0" />
                            </Polyline.RenderTransform>
                        </Polyline>
                        <Path Canvas.Left="75" Canvas.Top="50"
                            Fill="Red">
                            <Path.Data>
                                <EllipseGeometry x:Name="ellipseGeometry2" 
                                    Center="0 0"
                                    RadiusX="5"
                                    RadiusY="5" />
                            </Path.Data>
                        </Path>
                    </Canvas>
                </Border>
                <StackPanel>
                    <Button Name="startButton"
                        Margin="10"
                        Width="100"
                        Height="30">
                        시작
                    </Button>
                    <Button Name="stopButton"
                        Margin="0"
                        Width="100"
                        Height="30">
                        중단
                    </Button>
                    <StackPanel.Triggers>
                        <EventTrigger SourceName="startButton" RoutedEvent="Button.Click">
                            <BeginStoryboard Name="beginStoryboard">
                                <Storyboard>
                                    <ParallelTimeline RepeatBehavior="Forever">
                                        <DoubleAnimation
                                            Storyboard.TargetName="rotateTransform1" 
                                            Storyboard.TargetProperty="(RotateTransform.Angle)"
                                            RepeatBehavior="Forever" 
                                            From="0"
                                            To="360"
                                            Duration="0:0:5" />
                                        <ParallelTimeline RepeatBehavior="Forever">
                                            <DoubleAnimation 
                                                Storyboard.TargetName="rotateTransform2" 
                                                Storyboard.TargetProperty="Angle"
                                                RepeatBehavior="4x"
                                                From="0"
                                                To="360"
                                                Duration="0:0:2.5" />
                                            <DoubleAnimation 
                                                Storyboard.TargetName="rotateTransform2" 
                                                Storyboard.TargetProperty="CenterX"
                                                AutoReverse="True"
                                                From="0"
                                                To="25"
                                                Duration="0:0:5" />
                                            <DoubleAnimation 
                                                Storyboard.TargetName="rotateTransform2" 
                                                Storyboard.TargetProperty="CenterY"
                                                AutoReverse="True"
                                                From="0"
                                                To="50"
                                                Duration="0:0:5" />
                                            <PointAnimation 
                                                Storyboard.TargetName="ellipseGeometry2" 
                                                Storyboard.TargetProperty="Center"
                                                AutoReverse="True"
                                                From="0 0"
                                                To="25 50"
                                                Duration="0:0:5" />
                                        </ParallelTimeline>
                                    </ParallelTimeline>
                                </Storyboard>
                            </BeginStoryboard>            
                        </EventTrigger>
                        <EventTrigger SourceName="stopButton" RoutedEvent="Button.Click">
                            <StopStoryboard BeginStoryboardName="beginStoryboard" />
                        </EventTrigger>
                    </StackPanel.Triggers>
                </StackPanel>
            </WrapPanel>
        </ScrollViewer>
    </Border>
</Window>
728x90
반응형
그리드형
Posted by 사용자 icodebroker

댓글을 달아 주세요