■ RadioButton 엘리먼트에서 글래스 효과를 제공하는 라디오 버튼을 만드는 방법을 보여준다.
▶ MainApplication.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
<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> <Style TargetType="{x:Type TextBlock}"> <Setter Property="TextWrapping" Value="Wrap" /> <Setter Property="FontFamily" Value="Verdana" /> </Style> <LinearGradientBrush x:Key="GlassLinearGradientBrushKey" StartPoint="0 0" EndPoint="1 1" Opacity="0.75"> <LinearGradientBrush.GradientStops> <GradientStop Color="WhiteSmoke" Offset="0.2" /> <GradientStop Color="Transparent" Offset="0.4" /> <GradientStop Color="WhiteSmoke" Offset="0.5" /> <GradientStop Color="Transparent" Offset="0.75" /> <GradientStop Color="WhiteSmoke" Offset="0.9" /> <GradientStop Color="Transparent" Offset="1" /> </LinearGradientBrush.GradientStops> </LinearGradientBrush> <Style x:Key="SelectorRadioButtonStyleKey" TargetType="{x:Type RadioButton}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type RadioButton}"> <Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" ClipToBounds="true"> <Rectangle Name="outerRectangle" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" RadiusX="20" RadiusY="20" StrokeThickness="5" Stroke="{TemplateBinding Background}" Fill="Transparent" /> <Rectangle Name="innerRectangle" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" RadiusX="20" RadiusY="20" StrokeThickness="20" Stroke="Transparent" Fill="{TemplateBinding Background}" /> <Rectangle Name="glassRectangle" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" RadiusX="10" RadiusY="10" StrokeThickness="2" RenderTransformOrigin="0.5 0.5" Opacity="0" Fill="{StaticResource GlassLinearGradientBrushKey}"> <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> <DockPanel> <ContentPresenter Name="contentPresenter" Margin="15" TextBlock.Foreground="Black" Content="{TemplateBinding Content}" /> </DockPanel> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsFocused" Value="true"> <Setter TargetName="glassRectangle" Property="Rectangle.Opacity" Value="1" /> <Setter TargetName="innerRectangle" Property="Rectangle.Opacity" Value="1" /> </Trigger> <EventTrigger RoutedEvent="Mouse.MouseEnter"> <EventTrigger.Actions> <BeginStoryboard Name="mouseEnterBeginStoryboard"> <Storyboard> <DoubleAnimation Storyboard.TargetName="glassRectangle" Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Duration="00:00:00.5" From="1" To="0.9" /> <DoubleAnimation Storyboard.TargetName="glassRectangle" Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Duration="00:00:00.5" From="1" To="0.9" /> <DoubleAnimation Storyboard.TargetName="outerRectangle" Storyboard.TargetProperty="(Rectangle.RadiusX)" Duration="00:00:00.5" From="20" To="0" /> <DoubleAnimation Storyboard.TargetName="outerRectangle" Storyboard.TargetProperty="(Rectangle.RadiusY)" Duration="00:00:00.5" From="20" To="0" /> <DoubleAnimation Storyboard.TargetName="glassRectangle" Storyboard.TargetProperty="(Rectangle.Opacity)" Duration="00:00:00.1" From="0" To="1" /> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> <EventTrigger RoutedEvent="Mouse.MouseLeave"> <EventTrigger.Actions> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="outerRectangle" Storyboard.TargetProperty="(Rectangle.RadiusX)" Duration="00:00:00.5" From="0" To="20" /> <DoubleAnimation Storyboard.TargetName="outerRectangle" Storyboard.TargetProperty="(Rectangle.RadiusY)" Duration="00:00:00.5" From="0" To="20" /> <DoubleAnimation Storyboard.TargetName="glassRectangle" Storyboard.TargetProperty="(Rectangle.Opacity)" Duration="00:00:00.1" From="1" To="0" /> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> <EventTrigger RoutedEvent="RadioButton.Checked"> <EventTrigger.Actions> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="glassRectangle" Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Duration="00:00:00.1" To="0.1" AutoReverse="True" /> <DoubleAnimation Storyboard.TargetName="glassRectangle" Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Duration="00:00:00.1" To="0.1" AutoReverse="True" /> <DoubleAnimation Storyboard.TargetName="innerRectangle" Storyboard.TargetProperty="(Rectangle.Opacity)" Duration="00:00:00.5" To="0" /> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> <EventTrigger RoutedEvent="RadioButton.Unchecked"> <EventTrigger.Actions> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="innerRectangle" Storyboard.TargetProperty="(Rectangle.Opacity)" Duration="00:00:00.5" To="1.0" /> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> <Setter Property="Background" Value="White" /> </Style> </Application.Resources> </Application> |
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
<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="TestProject" Background="LightGray" FontFamily="나눔고딕코딩" FontSize="16"> <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"> <RadioButton Style="{StaticResource SelectorRadioButtonStyleKey}" Margin="10"> Using DrawingBrush Example </RadioButton> <RadioButton Style="{StaticResource SelectorRadioButtonStyleKey}" Margin="10"> Transform Example </RadioButton> <RadioButton Style="{StaticResource SelectorRadioButtonStyleKey}" Margin="10"> ImageDrawing Example </RadioButton> <RadioButton Style="{StaticResource SelectorRadioButtonStyleKey}" Margin="10"> Animate GeometryDrawing Example </RadioButton> </StackPanel> </Window> |