■ ControlTemplate 엘리먼트를 사용해 ContextMenu 엘리먼트를 정의하는 방법을 보여준다.
▶ 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 |
<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="ControlLightColorKey">White</Color> <Color x:Key="ControlMediumColorKey">#ff7381f9</Color> <Color x:Key="BorderMediumColorKeyKey">#ff888888</Color> <LinearGradientBrush x:Key="MenuPopupLinearGradientBrushKey" 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> <Style TargetType="{x:Type ContextMenu}"> <Setter Property="SnapsToDevicePixels" Value="True" /> <Setter Property="OverridesDefaultStyle" Value="True" /> <Setter Property="Grid.IsSharedSizeScope" Value="true" /> <Setter Property="HasDropShadow" Value="True" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ContextMenu}"> <Border Name="Border" Background="{StaticResource MenuPopupLinearGradientBrushKey}" BorderThickness="1"> <Border.BorderBrush> <SolidColorBrush Color="{StaticResource BorderMediumColorKeyKey}" /> </Border.BorderBrush> <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle" /> </Border> <ControlTemplate.Triggers> <Trigger Property="HasDropShadow" Value="true"> <Setter TargetName="Border" Property="Padding" Value="0 3 0 3" /> <Setter TargetName="Border" Property="CornerRadius" Value="4" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <TextBox HorizontalAlignment="Center" VerticalAlignment="Center" Width="200" Height="25" BorderThickness="1" BorderBrush="Black" VerticalContentAlignment="Center"> <TextBox.ContextMenu> <ContextMenu> <MenuItem Header="메뉴 1" /> <MenuItem Header="메뉴 2" /> <MenuItem Header="메뉴 3" /> </ContextMenu> </TextBox.ContextMenu> </TextBox> </Window> |