728x90
반응형
728x170
■ 애니메이션 버튼을 만드는 방법을 보여준다.
▶ 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>
▶ 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
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] DataGrid 클래스 : RowValidationRules 속성을 사용해 검증하기 (0) | 2017.06.11 |
---|---|
[C#/WPF] DataGrid 클래스 : 그룹핑, 정렬 및 필터링 사용하기 (0) | 2017.06.11 |
[C#/WPF] 방사형 패널 사용하기 (0) | 2017.06.11 |
[C#/WPF] MessageBox 클래스 : 메시지 박스 사용하기 (0) | 2017.06.11 |
[C#/WPF] DataGrid 클래스 : ADO.NET 엔터티 데이터 모델 바인딩 하기 (0) | 2017.06.11 |
[C#/WPF] DesignInstance 확장 태그 사용하기 (0) | 2017.06.11 |
[C#/WPF] ObservableCollection<T> 클래스 : 바인딩 설정하기 (0) | 2017.06.11 |
[C#/WPF] TreeViewItem 클래스 : ItemsSource 속성을 사용해 트리 뷰 만들기 (0) | 2017.06.11 |
[C#/WPF] NavigationWindow 엘리먼트 : 페이지 탐색하기 (0) | 2017.06.11 |
[C#/WPF] XAML용 UI 디버깅 도구 숨기기 (0) | 2017.05.30 |
댓글을 달아 주세요