■ ControlTemplate 엘리먼트를 사용해 DatePicker 엘리먼트를 정의하는 방법을 보여준다.
▶ 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 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 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
<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" FontFamily="나눔고딕코딩" FontSize="16"> <Window.Resources> <Color x:Key="ControlMediumColorKey">#ff7381f9</Color> <Color x:Key="ControlDarkColorKey">#ff211aa9</Color> <Color x:Key="ControlPressedColorKey">#ff211aa9</Color> <Color x:Key="BorderLightColorKey">#ffcccccc</Color> <Color x:Key="BorderDarkColorKey">#ff444444</Color> <Color x:Key="HeaderTopColorKey">#ffc5cbf9</Color> <Style x:Key="DatePickerCalendarStyleKey" TargetType="{x:Type Calendar}" BasedOn="{StaticResource {x:Type Calendar}}" /> <Style x:Key="DropDownButtonStyleKey" TargetType="Button"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Grid> <VisualStateManager.VisualStateGroups> <VisualStateGroup Name="CommonStates"> <VisualStateGroup.Transitions> <VisualTransition GeneratedDuration="0" /> <VisualTransition GeneratedDuration="00:00:00.1" To="MouseOver" /> <VisualTransition GeneratedDuration="00:00:00.1" To="Pressed" /> </VisualStateGroup.Transitions> <VisualState Name="Normal" /> <VisualState Name="MouseOver"> <Storyboard> <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Duration="00:00:00.001" BeginTime="0"> <SplineColorKeyFrame KeyTime="0" Value="#f2ffffff" /> </ColorAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[2].(GradientStop.Color)" Duration="00:00:00.001" BeginTime="0"> <SplineColorKeyFrame KeyTime="0" Value="#ccffffff" /> </ColorAnimationUsingKeyFrames> <ColorAnimation Storyboard.TargetName="Background" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" Duration="0" To="#ff448dca" /> <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[3].(GradientStop.Color)" Duration="00:00:00.001" BeginTime="0"> <SplineColorKeyFrame KeyTime="0" Value="#7fffffff" /> </ColorAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState Name="Pressed"> <Storyboard> <ColorAnimationUsingKeyFrames Storyboard.TargetName="Background" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" Duration="00:00:00.001" BeginTime="0"> <SplineColorKeyFrame KeyTime="0" Value="#ff448dca" /> </ColorAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames Storyboard.TargetName="Highlight" Storyboard.TargetProperty="(UIElement.Opacity)" Duration="00:00:00.001" BeginTime="0"> <SplineDoubleKeyFrame KeyTime="0" Value="1" /> </DoubleAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Duration="00:00:00.001" BeginTime="0"> <SplineColorKeyFrame KeyTime="0" Value="#f4ffffff" /> </ColorAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Duration="00:00:00.001" BeginTime="0"> <SplineColorKeyFrame KeyTime="0" Value="#eaffffff" /> </ColorAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[2].(GradientStop.Color)" Duration="00:00:00.001" BeginTime="0"> <SplineColorKeyFrame KeyTime="0" Value="#c6ffffff" /> </ColorAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[3].(GradientStop.Color)" Duration="00:00:00.001" BeginTime="0"> <SplineColorKeyFrame KeyTime="0" Value="#6bffffff" /> </ColorAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState Name="Disabled" /> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Grid HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0" Width="19" Height="18" Background="#11ffffff" FlowDirection="LeftToRight"> <Grid.ColumnDefinitions> <ColumnDefinition Width="20*" /> <ColumnDefinition Width="20*" /> <ColumnDefinition Width="20*" /> <ColumnDefinition Width="20*" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="23*" /> <RowDefinition Height="19*" /> <RowDefinition Height="19*" /> <RowDefinition Height="19*" /> </Grid.RowDefinitions> <Border Name="Highlight" Grid.Row="0" Grid.RowSpan="4" Grid.ColumnSpan="4" Margin="-1" CornerRadius="0 0 1 1" BorderThickness="1" Opacity="1"> <Border.BorderBrush> <SolidColorBrush Color="{DynamicResource ControlPressedColorKey}" /> </Border.BorderBrush> </Border> <Border Name="Background" Grid.Row="1" Grid.RowSpan="3" Grid.ColumnSpan="4" Margin="0 -1 0 0" CornerRadius="0.5" BorderBrush="#ffffffff" BorderThickness="1" Opacity="1"> <Border.Background> <SolidColorBrush Color="{DynamicResource ControlDarkColorKey}" /> </Border.Background> </Border> <Border Name="BackgroundGradient" Grid.Row="1" Grid.RowSpan="3" Grid.ColumnSpan="4" Margin="0 -1 0 0" CornerRadius="0.5" BorderBrush="#BF000000" BorderThickness="1" Opacity="1"> <Border.Background> <LinearGradientBrush StartPoint="0.7 0" EndPoint="0.7 1"> <GradientStop Color="#ffffffff" Offset="0" /> <GradientStop Color="#f9ffffff" Offset="0.375" /> <GradientStop Color="#e5ffffff" Offset="0.625" /> <GradientStop Color="#c6ffffff" Offset="1" /> </LinearGradientBrush> </Border.Background> </Border> <Rectangle Grid.RowSpan="1" Grid.ColumnSpan="4" StrokeThickness="1"> <Rectangle.Fill> <LinearGradientBrush StartPoint="0 0" EndPoint="0 1"> <GradientStop Color="{DynamicResource HeaderTopColorKey }" /> <GradientStop Offset="1" Color="{DynamicResource ControlMediumColorKey}" /> </LinearGradientBrush> </Rectangle.Fill> <Rectangle.Stroke> <LinearGradientBrush StartPoint="0.48 1.25" EndPoint="0.48 -1"> <GradientStop Color="#ff494949" /> <GradientStop Offset="1" Color="#ff9f9F9F" /> </LinearGradientBrush> </Rectangle.Stroke> </Rectangle> <Path Grid.Row="1" Grid.Column="0" Grid.RowSpan="3" Grid.ColumnSpan="4" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="4 3 4 3" Fill="#ff2f2f2f" RenderTransformOrigin="0.5 0.5" Stretch="Fill" Data="M 11.426758 8.4305077 L 11.749023 8.4305077 L 11.749023 16.331387 L 10.674805 16.331387 L 10.674805 10.299648 L 9.0742188 11.298672 L 9.0742188 10.294277 C 9.4788408 10.090176 9.9094238 9.8090878 10.365967 9.4510155 C 10.82251 9.0929432 11.176106 8.7527733 11.426758 8.4305077 z M 14.65086 8.4305077 L 18.566387 8.4305077 L 18.566387 9.3435936 L 15.671368 9.3435936 L 15.671368 11.255703 C 15.936341 11.058764 16.27293 10.960293 16.681133 10.960293 C 17.411602 10.960293 17.969301 11.178717 18.354229 11.615566 C 18.739157 12.052416 18.931622 12.673672 18.931622 13.479336 C 18.931622 15.452317 18.052553 16.438808 16.294415 16.438808 C 15.560365 16.438808 14.951641 16.234707 14.468243 15.826504 L14.881817 14.929531 C 15.368796 15.326992 15.837872 15.525723 16.289043 15.525723 C 17.298809 15.525723 17.803692 14.895514 17.803692 13.635098 C 17.803692 12.460618 17.305971 11.873379 16.310528 11.873379 C 15.83071 11.873379 15.399232 12.079271 15.016094 12.491055 L 14.65086 12.238613 z" /> <Ellipse Grid.ColumnSpan="4" HorizontalAlignment="Center" VerticalAlignment="Center" Width="3" Height="3" StrokeThickness="0" Fill="#ffffffff" /> <Border Name="DisabledVisual" Grid.Row="0" Grid.RowSpan="4" Grid.ColumnSpan="4" CornerRadius="0 0 0.5 0.5" BorderThickness="1" BorderBrush="#b2ffffff" Opacity="0" /> </Grid> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="DatePickerStyleKey" TargetType="{x:Type DatePicker}"> <Setter Property="Foreground" Value="#ff333333" /> <Setter Property="IsTodayHighlighted" Value="True" /> <Setter Property="SelectedDateFormat" Value="Short" /> <Setter Property="Padding" Value="2" /> <Setter Property="BorderThickness" Value="1" /> <Setter Property="HorizontalContentAlignment" Value="Stretch" /> <Setter Property="CalendarStyle" Value="{DynamicResource DatePickerCalendarStyleKey}" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type DatePicker}"> <Border BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}"> <Border.BorderBrush> <LinearGradientBrush StartPoint="0.5 0" EndPoint="0.5 1"> <GradientStop Offset="0" Color="{DynamicResource BorderLightColorKey}" /> <GradientStop Offset="1" Color="{DynamicResource BorderDarkColorKey }" /> </LinearGradientBrush> </Border.BorderBrush> <Border.Background> <LinearGradientBrush StartPoint="0.5 0" EndPoint="0.5 1"> <GradientStop Offset="0" Color="{DynamicResource HeaderTopColorKey }" /> <GradientStop Offset="1" Color="{DynamicResource ControlMediumColorKey}" /> </LinearGradientBrush> </Border.Background> <VisualStateManager.VisualStateGroups> <VisualStateGroup Name="CommonStates"> <VisualState Name="Normal" /> <VisualState Name="Disabled"> <Storyboard> <DoubleAnimation Storyboard.TargetName="PART_DisabledVisual" Storyboard.TargetProperty="Opacity" Duration="0" To="1" /> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Grid Name="PART_Root" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <Button Name="PART_Button" Grid.Row="0" Grid.Column="1" Style="{StaticResource DropDownButtonStyleKey}" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="3 0 3 0" Foreground="{TemplateBinding Foreground}" Focusable="False" /> <DatePickerTextBox Name="PART_TextBox" Grid.Row="0" Grid.Column="0" Foreground="{TemplateBinding Foreground}" Focusable="{TemplateBinding Focusable}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" /> <Grid Name="PART_DisabledVisual" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" IsHitTestVisible="False" Opacity="0"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <Rectangle Grid.Row="0" Grid.Column="0" RadiusX="1" RadiusY="1" Fill="#a5ffffff" /> <Rectangle Grid.Row="0" Grid.Column="1" Margin="3 0 3 0" Width="19" Height="18" RadiusX="1" RadiusY="1" Fill="#a5ffffff" /> <Popup Name="PART_Popup" Placement="Bottom" PlacementTarget="{Binding ElementName=PART_TextBox}" AllowsTransparency="True" StaysOpen="False" /> </Grid> </Grid> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Horizontal"> <DatePicker VerticalAlignment="Center" /> <DatePicker Style="{StaticResource DatePickerStyleKey}" Margin="10 0 0 0" VerticalAlignment="Center" /> </StackPanel> </Window> |