첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
다운로드

▶ MainApplication.xaml

<Application 
    x:Class="TestProject.MainApplication"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="MainWindow.xaml">
    <Application.Resources>
        <GradientStopCollection x:Key="GlassGradientStopCollectionKey">
            <GradientStop Offset="0.2"  Color="WhiteSmoke"  />
            <GradientStop Offset="0.4"  Color="Transparent" />
            <GradientStop Offset="0.5"  Color="WhiteSmoke"  />
            <GradientStop Offset="0.75" Color="Transparent" />
            <GradientStop Offset="0.9"  Color="WhiteSmoke"  />
            <GradientStop Offset="1"    Color="Transparent" />
        </GradientStopCollection>
        <LinearGradientBrush x:Key="GlassLinearGradientBrushKey" 
            StartPoint="0 0"
            EndPoint="1 1"
            Opacity="0.75" 
            GradientStops="{StaticResource GlassGradientStopCollectionKey}" />
        <LinearGradientBrush x:Key="ButtonLinearGradientBrushKey" 
            StartPoint="0 0"
            EndPoint="1 1">
            <GradientStop Offset="0"   Color="DarkGray" />
            <GradientStop Offset="0.5" Color="#ccccff"  />
            <GradientStop Offset="1"   Color="DarkGray" />
        </LinearGradientBrush>
        <Style TargetType="{x:Type Button}">
            <Setter Property="Margin"     Value="10" />
            <Setter Property="Width"      Value="90" />
            <Setter Property="Background" Value="{StaticResource ButtonLinearGradientBrushKey}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid
                            Width="{TemplateBinding Width}" 
                            Height="{TemplateBinding Height}"
                            ClipToBounds="True">
                            <Rectangle x:Name="outerRectangle" 
                                HorizontalAlignment="Stretch" 
                                VerticalAlignment="Stretch" 
                                RadiusX="20"
                                RadiusY="20"
                                StrokeThickness="5" 
                                Stroke="{TemplateBinding Background}" 
                                Fill="Transparent" />
                            <Rectangle x:Name="innerRectangle" 
                                HorizontalAlignment="Stretch" 
                                VerticalAlignment="Stretch"
                                RadiusX="20"
                                RadiusY="20"
                                StrokeThickness="20" 
                                Stroke="Transparent" 
                                Fill="{TemplateBinding Background}" />
                            <Rectangle x:Name="glassCubeRectangle"
                                HorizontalAlignment="Stretch"
                                VerticalAlignment="Stretch"
                                RadiusX="10"
                                RadiusY="10"
                                StrokeThickness="2"
                                Opacity="0"
                                Fill="{StaticResource GlassLinearGradientBrushKey}"
                                RenderTransformOrigin="0.5 0.5">
                                <Rectangle.Stroke>
                                    <LinearGradientBrush
                                        StartPoint="0.5 0"
                                        EndPoint="0.5 1">
                                        <LinearGradientBrush.GradientStops>
                                            <GradientStop Offset="0.0" Color="LightBlue" />
                                            <GradientStop Offset="1.0" Color="Gray"      />
                                        </LinearGradientBrush.GradientStops>
                                    </LinearGradientBrush>
                                </Rectangle.Stroke>
                                <Rectangle.RenderTransform>
                                    <TransformGroup>
                                        <ScaleTransform />
                                        <RotateTransform />
                                    </TransformGroup>
                                </Rectangle.RenderTransform>
                                <Rectangle.BitmapEffect>
                                    <BevelBitmapEffect />
                                </Rectangle.BitmapEffect>
                            </Rectangle>
                            <DockPanel Name="myContentPresenterDockPanel">
                                <ContentPresenter x:Name="contentPresenter"
                                    Margin="20" 
                                    Content="{TemplateBinding Content}" 
                                    TextBlock.Foreground="Black" />
                            </DockPanel>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter
                                    TargetName="outerRectangle"
                                    Property="Rectangle.Stroke"
                                    Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
                                <Setter
                                    TargetName="glassCubeRectangle"
                                    Property="Rectangle.Opacity"
                                    Value="1" />
                                <Setter
                                    TargetName="contentPresenter"
                                    Property="ContentPresenter.BitmapEffect">
                                    <Setter.Value>
                                        <BlurBitmapEffect Radius="1" />
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                            <Trigger Property="IsFocused" Value="true">
                                <Setter
                                    TargetName="glassCubeRectangle"
                                    Property="Rectangle.Opacity"
                                    Value="1" />
                                <Setter
                                    TargetName="outerRectangle"
                                    Property="Rectangle.Stroke"
                                    Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
                                <Setter
                                    TargetName="glassCubeRectangle"
                                    Property="Rectangle.Opacity"
                                    Value="1" />
                            </Trigger>
                            <EventTrigger RoutedEvent="Mouse.MouseEnter">
                                <EventTrigger.Actions>
                                    <BeginStoryboard Name="mouseEnterBeginStoryboard">
                                        <Storyboard>
                                            <DoubleAnimation
                                                Storyboard.TargetName="glassCubeRectangle" 
                                                Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"
                                                By="-0.1"
                                                Duration="0:0:0.5" />
                                            <DoubleAnimation
                                                Storyboard.TargetName="glassCubeRectangle" 
                                                Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"
                                                By="-0.1"
                                                Duration="0:0:0.5" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger.Actions>
                            </EventTrigger>
                            <EventTrigger RoutedEvent="Mouse.MouseLeave">
                                <EventTrigger.Actions>
                                    <StopStoryboard BeginStoryboardName="mouseEnterBeginStoryboard" />
                                </EventTrigger.Actions>
                            </EventTrigger>
                            <EventTrigger RoutedEvent="Button.Click">
                                <EventTrigger.Actions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation
                                                Storyboard.TargetName="glassCubeRectangle" 
                                                Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[1].(RotateTransform.Angle)"
                                                By="360"
                                                Duration="0:0:0.5" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger.Actions>
                            </EventTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Application.Resources>
</Application>

 

728x90

 

▶ 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"
    Title="애니메이션 버튼 사용하기"
    Width="600" 
    Height="450"
    Background="Black"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <StackPanel HorizontalAlignment="Left">
        <Button>버튼 1</Button>
        <Button>버튼 2</Button>
        <Button>버튼 3</Button>
    </StackPanel>
</Window>
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요