■ Style 엘리먼트의 TargetType 속성을 사용해 MenuItem 엘리먼트 스타일 설정하는 방법을 보여준다.
▶ 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 |
<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> <Style TargetType="{x:Type MenuItem}"> <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.MenuHighlightBrushKey}}"/> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.MenuTextBrushKey }}"/> <Style.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter Property="Foreground" Value="Red" /> <Setter Property="FontSize" Value="16" /> <Setter Property="FontStyle" Value="Italic" /> </Trigger> </Style.Triggers> </Style> </Window.Resources> <Button HorizontalAlignment="Center" Height="30" Padding="10 0 10 0"> Button with Context Menu <Button.ContextMenu> <ContextMenu StaysOpen="true"> <MenuItem Header="File" /> <MenuItem Header="Save" /> <MenuItem Header="SaveAs" /> <MenuItem Header="Recent Files"> <MenuItem Header="ReadMe.txt" /> <MenuItem Header="Schedule.xls" /> </MenuItem> </ContextMenu> </Button.ContextMenu> </Button> </Window> |