■ ControlTemplate 엘리먼트를 사용해 Frame 엘리먼트 정의하는 방법을 보여준다.
▶ ContentPage.xaml
1 2 3 4 5 6 7 8 9 10 11 |
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Title="컨텐트 페이지"> <Grid> <Ellipse Margin="50" Fill="RoyalBlue" /> </Grid> </Page> |
▶ 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 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 |
<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="DisabledControlDarkColorKey">#ffc5cbf9</Color> <Color x:Key="DisabledForegroundColorKey">#ff888888</Color> <Color x:Key="ControlLightColorKey">White</Color> <Color x:Key="ControlMediumColorKey">#ff7381f9</Color> <Color x:Key="ControlDarkColorKey">#ff211aa9</Color> <Color x:Key="ControlMouseOverColorKey">#ff3843c4</Color> <Color x:Key="ControlPressedColorKey">#ff211aa9</Color> <Color x:Key="GlyphColorKey">#ff444444</Color> <Color x:Key="BorderLightColorKey">#ffcccccc</Color> <Color x:Key="BorderMediumColorKey">#ff888888</Color> <Color x:Key="BorderDarkColorKey">#ff444444</Color> <Color x:Key="NavButtonFrameColorKey">#ff3843c4</Color> <LinearGradientBrush x:Key="MenuPopupBrushKey" StartPoint="0.5 0" EndPoint="0.5 1"> <GradientStop Offset="0" Color="{DynamicResource ControlLightColorKey }" /> <GradientStop Offset="0.5" Color="{DynamicResource ControlMediumColorKey}" /> <GradientStop Offset="1" Color="{DynamicResource ControlLightColorKey }" /> </LinearGradientBrush> <JournalEntryUnifiedViewConverter x:Key="JournalEntryUnifiedViewConverterKey" /> <Style x:Key="FrameButtonStyleKey" TargetType="{x:Type Button}"> <Setter Property="OverridesDefaultStyle" Value="true" /> <Setter Property="Command" Value="NavigationCommands.BrowseBack" /> <Setter Property="Focusable" Value="false" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Grid> <VisualStateManager.VisualStateGroups> <VisualStateGroup Name="CommonStates"> <VisualState Name="Normal" /> <VisualState Name="MouseOver"> <Storyboard> <ColorAnimationUsingKeyFrames Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)"> <EasingColorKeyFrame KeyTime="0" Value="{StaticResource ControlMouseOverColorKey}" /> </ColorAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState Name="Pressed"> <Storyboard> <ColorAnimationUsingKeyFrames Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)"> <EasingColorKeyFrame KeyTime="0" Value="{StaticResource ControlPressedColorKey}" /> </ColorAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState Name="Disabled"> <Storyboard> <ColorAnimationUsingKeyFrames Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)"> <EasingColorKeyFrame KeyTime="0" Value="{StaticResource DisabledControlDarkColorKey}" /> </ColorAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="arrowPath" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)"> <EasingColorKeyFrame KeyTime="0" Value="{StaticResource DisabledForegroundColorKey}" /> </ColorAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Ellipse Name="ellipse" Width="16" Height="16" StrokeThickness="1"> <Ellipse.Stroke> <SolidColorBrush Color="{DynamicResource NavButtonFrameColorKey}" /> </Ellipse.Stroke> <Ellipse.Fill> <LinearGradientBrush StartPoint="0 0" EndPoint="0 1"> <LinearGradientBrush.GradientStops> <GradientStopCollection> <GradientStop Color="{DynamicResource ControlLightColorKey }" /> <GradientStop Offset="1.0" Color="{DynamicResource ControlMediumColorKey}" /> </GradientStopCollection> </LinearGradientBrush.GradientStops> </LinearGradientBrush> </Ellipse.Fill> </Ellipse> <Path Name="arrowPath" Margin="0 0 2 0" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M 4 0 L 0 4 L 4 8 Z" > <Path.Fill> <SolidColorBrush Color="{DynamicResource GlyphColorKey}" /> </Path.Fill> </Path> </Grid> <ControlTemplate.Triggers> <Trigger Property="Command" Value="{x:Static NavigationCommands.BrowseForward}"> <Setter TargetName="arrowPath" Property="Data" Value="M 0 0 L 4 4 L 0 8 z" /> <Setter TargetName="arrowPath" Property="Margin" Value="2 0 0 0" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="FrameMenuStyleKey" TargetType="{x:Type Menu}"> <Setter Property="OverridesDefaultStyle" Value="true" /> <Setter Property="KeyboardNavigation.TabNavigation" Value="None" /> <Setter Property="IsMainMenu" Value="false" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Menu}"> <DockPanel IsItemsHost="true" /> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="FrameHeaderMenuItemStyleKey" TargetType="{x:Type MenuItem}"> <Setter Property="OverridesDefaultStyle" Value="true" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type MenuItem}"> <Grid> <Popup Name="PART_Popup" Placement="Bottom" VerticalOffset="2" AllowsTransparency="True" PopupAnimation="Fade" Focusable="False" IsOpen="{TemplateBinding IsSubmenuOpen}"> <Border BorderThickness="1" Background="{DynamicResource MenuPopupBrushKey}"> <Border.BorderBrush> <SolidColorBrush Color="{StaticResource BorderMediumColorKey}" /> </Border.BorderBrush> <StackPanel IsItemsHost="true" Margin="2" KeyboardNavigation.TabNavigation="Cycle" KeyboardNavigation.DirectionalNavigation="Cycle" /> </Border> </Popup> <Grid Width="24" Background="Transparent" HorizontalAlignment="Right"> <Border x:Name="highlightBorder" CornerRadius="2" BorderThickness="1" Visibility="Hidden"> <Border.BorderBrush> <LinearGradientBrush StartPoint="0 0" EndPoint="0 1"> <LinearGradientBrush.GradientStops> <GradientStopCollection> <GradientStop Offset="0.0" Color="{DynamicResource BorderLightColorKey}" /> <GradientStop Offset="1.0" Color="{DynamicResource BorderDarkColorKey }" /> </GradientStopCollection> </LinearGradientBrush.GradientStops> </LinearGradientBrush> </Border.BorderBrush> <Border.Background> <LinearGradientBrush StartPoint="0 0" EndPoint="0 1"> <LinearGradientBrush.GradientStops> <GradientStopCollection> <GradientStop Color="{DynamicResource ControlLightColorKey }" /> <GradientStop Offset="1.0" Color="{DynamicResource ControlMouseOverColorKey}" /> </GradientStopCollection> </LinearGradientBrush.GradientStops> </LinearGradientBrush> </Border.Background> </Border> <Path x:Name="arrowPath" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0 2 4 0" SnapsToDevicePixels="false" StrokeLineJoin="Round" Data="M 0 0 L 4 4 L 8 0 Z"> <Path.Stroke> <SolidColorBrush Color="{DynamicResource GlyphColorKey}" /> </Path.Stroke> </Path> </Grid> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsHighlighted" Value="true"> <Setter TargetName="highlightBorder" Property="Visibility" Value="Visible" /> </Trigger> <Trigger Property="IsSubmenuOpen" Value="true"> <Setter TargetName="highlightBorder" Property="BorderBrush"> <Setter.Value> <LinearGradientBrush StartPoint="0 0" EndPoint="0 1"> <GradientBrush.GradientStops> <GradientStopCollection> <GradientStop Offset="0.0" Color="{DynamicResource BorderDarkColorKey }" /> <GradientStop Offset="1.0" Color="{DynamicResource BorderMediumColorKey}" /> </GradientStopCollection> </GradientBrush.GradientStops> </LinearGradientBrush> </Setter.Value> </Setter> <Setter TargetName="highlightBorder" Property="Background"> <Setter.Value> <LinearGradientBrush StartPoint="0 0" EndPoint="0 1"> <GradientStop Offset="0" Color="{DynamicResource ControlLightColorKey }" /> <GradientStop Offset="0.984" Color="{DynamicResource ControlPressedColorKey}" /> </LinearGradientBrush> </Setter.Value> </Setter> </Trigger> <Trigger Property="IsEnabled" Value="false"> <Setter TargetName="arrowPath" Property="Fill"> <Setter.Value> <SolidColorBrush Color="{DynamicResource DisabledForegroundColorKey}" /> </Setter.Value> </Setter> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="FrameSubmenuItemStyleKey" TargetType="{x:Type MenuItem}"> <Setter Property="OverridesDefaultStyle" Value="true" /> <Setter Property="Header" Value="{Binding (JournalEntry.Name)}" /> <Setter Property="Command" Value="NavigationCommands.NavigateJournal" /> <Setter Property="CommandTarget" Value="{Binding TemplatedParent, RelativeSource={RelativeSource AncestorType={x:Type Menu}}}" /> <Setter Property="CommandParameter" Value="{Binding RelativeSource={RelativeSource Self}}" /> <Setter Property="JournalEntryUnifiedViewConverter.JournalEntryPosition" Value="{Binding (JournalEntryUnifiedViewConverter.JournalEntryPosition)}" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type MenuItem}"> <Border Name="border" BorderThickness="1"> <Grid Background="Transparent" SnapsToDevicePixels="true" Height="35" Width="250"> <Path Name="glyphPath" HorizontalAlignment="Left" Margin="7 5" Width="10" Height="10" StrokeThickness="2" StrokeStartLineCap="Triangle" StrokeEndLineCap="Triangle" SnapsToDevicePixels="false"> <Path.Stroke> <SolidColorBrush Color="{DynamicResource GlyphColorKey}" /> </Path.Stroke> </Path> <ContentPresenter ContentSource="Header" Margin="24 5,50,5" /> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="JournalEntryUnifiedViewConverter.JournalEntryPosition" Value="Current"> <Setter TargetName="glyphPath" Property="Data" Value="M 0 5 L 2.5 8 L 7 3 " /> </Trigger> <Trigger Property="IsHighlighted" Value="true"> <Setter TargetName="border" Property="Background"> <Setter.Value> <LinearGradientBrush StartPoint="0.5 0" EndPoint="0.5 1"> <GradientStop Offset="0" Color="Transparent" /> <GradientStop Offset="1" Color="{DynamicResource ControlMouseOverColorKey}" /> </LinearGradientBrush> </Setter.Value> </Setter> <Setter TargetName="border" Property="BorderBrush"> <Setter.Value> <LinearGradientBrush StartPoint="0.5 0" EndPoint="0.5 1"> <GradientStop Offset="0" Color="{DynamicResource BorderMediumColorKey}" /> <GradientStop Offset="1" Color="Transparent" /> </LinearGradientBrush> </Setter.Value> </Setter> </Trigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsHighlighted" Value="true" /> <Condition Property="JournalEntryUnifiedViewConverter.JournalEntryPosition" Value="Forward" /> </MultiTrigger.Conditions> <Setter TargetName="glyphPath" Property="Data" Value="M 3 1 L 7 5 L 3 9 z" /> <Setter TargetName="glyphPath" Property="Stroke" Value="{x:Null}" /> <Setter TargetName="glyphPath" Property="Fill"> <Setter.Value> <SolidColorBrush Color="{StaticResource GlyphColorKey}" /> </Setter.Value> </Setter> </MultiTrigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsHighlighted" Value="true" /> <Condition Property="JournalEntryUnifiedViewConverter.JournalEntryPosition" Value="Back" /> </MultiTrigger.Conditions> <Setter TargetName="glyphPath" Property="Data" Value="M 7 1 L 3 5 L 7 9 z" /> <Setter TargetName="glyphPath" Property="Stroke" Value="{x:Null}" /> <Setter TargetName="glyphPath" Property="Fill"> <Setter.Value> <SolidColorBrush Color="{StaticResource GlyphColorKey}" /> </Setter.Value> </Setter> </MultiTrigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="{x:Type Frame}" TargetType="{x:Type Frame}"> <Setter Property="SnapsToDevicePixels" Value="true" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Frame}"> <DockPanel> <Border DockPanel.Dock="Top" Height="22" BorderThickness="1"> <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> <Grid> <Grid.Background> <LinearGradientBrush StartPoint="0 0" EndPoint="0 1"> <LinearGradientBrush.GradientStops> <GradientStopCollection> <GradientStop Offset="0.0" Color="{DynamicResource ControlLightColorKey }" /> <GradientStop Offset="1.0" Color="{DynamicResource ControlMediumColorKey}" /> </GradientStopCollection> </LinearGradientBrush.GradientStops> </LinearGradientBrush> </Grid.Background> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="16" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <Menu Name="navigationMenu" Grid.ColumnSpan="3" Style="{StaticResource FrameMenuStyleKey}" VerticalAlignment="Center" Margin="1 0 0 0" Height="16"> <MenuItem Style="{StaticResource FrameHeaderMenuItemStyleKey}" ItemContainerStyle="{StaticResource FrameSubmenuItemStyleKey}" IsSubmenuOpen="{Binding (MenuItem.IsSubmenuOpen), Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"> <MenuItem.ItemsSource> <MultiBinding Converter="{StaticResource JournalEntryUnifiedViewConverterKey}"> <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="BackStack" /> <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="ForwardStack" /> </MultiBinding> </MenuItem.ItemsSource> </MenuItem> </Menu> <Path Grid.Column="0" Grid.ColumnSpan="3" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="2,1.5,0,1.5" StrokeThickness="1" Stroke="{x:Null}" SnapsToDevicePixels="false" IsHitTestVisible="false" Data="M 15 14 Q 18 12.9 20.9 14 A 8.3 8.3 0 0 0 35.7 8.7 A 8.3 8.3 0 0 0 25.2 0.6 Q 18 3.3 10.8 0.6 A 8.3 8.3 0 0 0 0.3 8.7 A 8.3 8.3 0 0 0 15 14 z"> <Path.Fill> <LinearGradientBrush StartPoint="0.5 0" EndPoint="0.5 1"> <GradientStop Offset="0" Color="{DynamicResource ControlMediumColorKey}" /> <GradientStop Offset="1" Color="{DynamicResource ControlDarkColorKey }" /> </LinearGradientBrush> </Path.Fill> </Path> <Button Grid.Column="0" Style="{StaticResource FrameButtonStyleKey}" Margin="2.7 1.5 1.3 1.5" Command="NavigationCommands.BrowseBack" Content="M 4 0 L 0 4 L 4 8 Z" /> <Button Grid.Column="1" Style="{StaticResource FrameButtonStyleKey}" Margin="1.3 1.5,0,1.5" Command="NavigationCommands.BrowseForward" Content="M 4 0 L 0 4 L 4 8 Z" /> </Grid> </Border> <Border BorderThickness="1"> <Border.BorderBrush> <SolidColorBrush Color="{DynamicResource BorderMediumColorKey}" /> </Border.BorderBrush> <ContentPresenter Name="PART_FrameCP" Width="640" Height="458" /> </Border> </DockPanel> <ControlTemplate.Triggers> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="CanGoForward" Value="false" /> <Condition Property="CanGoBack" Value="false" /> </MultiTrigger.Conditions> <Setter TargetName="navigationMenu" Property="IsEnabled" Value="false" /> </MultiTrigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <Frame Margin="10" Source="ContentPage.xaml" /> </Window> |