첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.

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"
    xmlns:o="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options" 
    Width="800"
    Height="600"
    Title="SolidColorBrush 클래스 : Color/Opacity 속성 애니메이션 설정하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Window.Resources>
        <DrawingBrush x:Key="checkeredBackground" 
            ViewportUnits="Absolute"
            Viewport="0 0 10 10"
            TileMode="Tile"
            o:Freeze="True">
            <DrawingBrush.Drawing>
                <DrawingGroup>
                    <GeometryDrawing Brush="White">
                        <GeometryDrawing.Geometry>
                            <RectangleGeometry Rect="0 0 1 1" />
                        </GeometryDrawing.Geometry>
                    </GeometryDrawing>
                    <GeometryDrawing
                        Brush="#e2e2e2"
                        Geometry="M 0 0 L 0 0.5 0.5 0.5 0.5 1 1 1 1 0.5 0.5 0.5 0.5 0" />
                </DrawingGroup>
            </DrawingBrush.Drawing>
        </DrawingBrush>
        <Style x:Key="checkeredRectangleStyle">
            <Setter Property="Rectangle.Stroke"          Value="Black"                                />
            <Setter Property="Rectangle.StrokeThickness" Value="1"                                    />
            <Setter Property="Rectangle.Fill"            Value="{StaticResource checkeredBackground}" />
        </Style>
    </Window.Resources>
    <Grid 
        HorizontalAlignment="Center"
        VerticalAlignment="Center">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="10"   />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="10"   />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*"    />
        </Grid.RowDefinitions>
        <Rectangle Grid.Row="1"  Grid.Column="0" Grid.ColumnSpan="5"
            Style="{StaticResource checkeredRectangleStyle}"
            RadiusX="10"
            RadiusY="10"
            Stroke="#9999ff" />
        <Label Grid.Row="0" Grid.Column="0"
            HorizontalAlignment="Center"
            FontWeight="Bold">
            Color 속성 애니메이션
        </Label>
        <Rectangle Grid.Row="1" Grid.Column="0"
            Width="100"
            Height="100"
            Stroke="Black"
            StrokeThickness="1"
            Margin="10"
            HorizontalAlignment="Center">
            <Rectangle.Fill>
                <SolidColorBrush x:Name="solidColorBrush1"
                    Color="Blue" />
            </Rectangle.Fill>
        </Rectangle>
        <Button Grid.Row="2" Grid.Column="0"
            HorizontalAlignment="Center"
            Margin="10"
            Padding="5">
            애니메이션 시작
            <Button.Triggers>
                <EventTrigger RoutedEvent="Button.Click">
                    <BeginStoryboard>
                        <Storyboard>
                            <ColorAnimation
                                Storyboard.TargetName="solidColorBrush1"
                                Storyboard.TargetProperty="Color"
                                From="Blue"
                                To="Red"
                                Duration="0:0:10" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Button.Triggers>
        </Button>
        <Label Grid.Row="0" Grid.Column="2"
            HorizontalAlignment="Center"
            FontWeight="Bold">
            Opacity 속성 애니메이션
        </Label>
        <Rectangle Grid.Row="1" Grid.Column="2"
            HorizontalAlignment="Center"
            Margin="10"
            Width="100"
            Height="100"
            Stroke="Black"
            StrokeThickness="1">
            <Rectangle.Fill>
                <SolidColorBrush x:Name="solidColorBrush2"
                    Color="Blue" />
            </Rectangle.Fill>
        </Rectangle>
        <Button Grid.Row="2" Grid.Column="2"
            HorizontalAlignment="Center"
            Margin="10"
            Padding="10">
            애니메이션 시작
            <Button.Triggers>
                <EventTrigger RoutedEvent="Button.Click">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation
                                Storyboard.TargetName="solidColorBrush2"
                                Storyboard.TargetProperty="Opacity"
                                From="1.0"
                                To="0.0"
                                Duration="0:0:10" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Button.Triggers>
        </Button>
        <Label Grid.Row="0" Grid.Column="4"
            HorizontalAlignment="Center"
            FontWeight="Bold">
            Color 속성 애니메이션
        </Label>
        <Rectangle Grid.Row="1" Grid.Column="4"
            HorizontalAlignment="Center"
            Margin="10"
            Width="100"
            Height="100"
            Stroke="Black"
            StrokeThickness="1">
            <Rectangle.Fill>
                <SolidColorBrush x:Name="solidColorBrush3"
                    Color="Blue" />
            </Rectangle.Fill>
        </Rectangle>
        <Button Grid.Row="2" Grid.Column="4"
            HorizontalAlignment="Center"
            Margin="10"
            Padding="5">
            애니메이션 시작
            <Button.Triggers>
                <EventTrigger RoutedEvent="Button.Click">
                    <BeginStoryboard>
                        <Storyboard>
                            <ColorAnimation
                                Storyboard.TargetName="solidColorBrush3"
                                Storyboard.TargetProperty="Color"
                                From="Blue"
                                To="#00ff0000"
                                Duration="0:0:10" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Button.Triggers>
        </Button>
    </Grid>
</Window>
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요