■ ControlTemplate 엘리먼트를 사용해 전원 버튼을 만드는 ToggleButton 엘리먼트를 정의하는 방법을 보여준다.
▶ 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 |
<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="#2a2a2a" FontFamily="나눔고딕코딩" FontSize="16"> <Window.Resources> <!-- 적색 전원 버튼 드로잉 이미지 리소스 --> <Geometry x:Key="RedPowerButtonGeometry1Key"> F 0 M 65183 72166 z M 0 0 z M 48128 10919 C 46433 9999 44313 10626 43393 12321 42472 14016 43100 16136 44795 17056 53063 21547 58199 30176 58199 39575 58199 53695 46712 65183 32592 65183 18472 65183 6984 53695 6984 39575 6984 30217 12087 21606 20302 17103 21993 16176 22612 14053 21685 12362 20758 10671 18635 10051 16944 10979 6493 16709 0 27666 0 39575 0 57546 14620 72166 32591 72166 50562 72166 65182 57546 65182 39575 65182 27614 58647 16634 48128 10919 z </Geometry> <Geometry x:Key="RedPowerButtonGeometry2Key"> F 0 M 65183 72166 z M 0 0 z M 32591 30263 C 34519 30263 36083 28700 36083 26771 L 36083 3492 C 36083 1563 34519 0 32591 0 30663 0 29099 1563 29099 3492 L 29099 26771 C 29099 28699 30663 30263 32591 30263 z </Geometry> <DrawingGroup x:Key="RedPowerButtonDrawingGroupKey" ClipGeometry="M0,0 V72166 H65183 V0 H0 Z"> <DrawingGroup Opacity="1"> <DrawingGroup Opacity="1"> <DrawingGroup Opacity="1"> <GeometryDrawing Brush="#ffff0000" Geometry="{StaticResource RedPowerButtonGeometry1Key}" /> <GeometryDrawing Brush="#ffff0000" Geometry="{StaticResource RedPowerButtonGeometry2Key}" /> </DrawingGroup> </DrawingGroup> </DrawingGroup> </DrawingGroup> <DrawingImage x:Key="RedPowerButtonDrawingImageKey" Drawing="{StaticResource RedPowerButtonDrawingGroupKey}" /> <ImageBrush x:Key="RedPowerButtonDrawingImageBrushKey" Stretch="Uniform" ImageSource="{StaticResource RedPowerButtonDrawingImageKey}" /> <!-- 백색 전원 버튼 드로잉 이미지 리소스 --> <Geometry x:Key="WhitePowerButtonGeometry1Key"> F 0 M 68925 76310 z M 0 0 z M 50892 11546 C 49100 10573 46858 11236 45885 13028 44912 14820 45575 17062 47367 18035 56110 22784 61540 31908 61540 41847 61540 56778 49393 68925 34462 68925 19531 68925 7384 56778 7384 41847 7384 31952 12780 22847 21467 18085 23255 17105 23910 14860 22930 13072 21950 11284 19705 10629 17917 11609 6865 17668 0 29254 0 41847 0 60850 15460 76310 34463 76310 53466 76310 68926 60850 68926 41847 68926 29199 62016 17588 50893 11546 z </Geometry> <Geometry x:Key="WhitePowerButtonGeometry2Key"> F 0 M 68925 76310 z M 0 0 z M 34463 32001 C 36502 32001 38156 30348 38156 28309 L 38156 3693 C 38156 1654 36503 0 34463 0 32424 0 30770 1653 30770 3693 L 30770 28309 C 30770 30348 32423 32001 34463 32001 z </Geometry> <DrawingGroup x:Key="WhitePowerButtonDrawingGroupKey" ClipGeometry="M0,0 V76310 H68925 V0 H0 Z"> <DrawingGroup Opacity="1"> <DrawingGroup Opacity="1"> <DrawingGroup Opacity="1"> <GeometryDrawing Brush="#ffffffff" Geometry="{StaticResource WhitePowerButtonGeometry1Key}" /> <GeometryDrawing Brush="#ffffffff" Geometry="{StaticResource WhitePowerButtonGeometry2Key}" /> </DrawingGroup> </DrawingGroup> </DrawingGroup> </DrawingGroup> <DrawingImage x:Key="WhitePowerButtonDrawingImageKey" Drawing="{StaticResource WhitePowerButtonDrawingGroupKey}" /> <ImageBrush x:Key="WhitePowerButtonImageBrushKey" Stretch="Uniform" ImageSource="{StaticResource WhitePowerButtonDrawingImageKey}" /> <!-- 전원 버튼 스타일 리소스 --> <Style x:Key="PowerButtonStyleKey" TargetType="Button"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Border x:Name="border" Background="{StaticResource RedPowerButtonDrawingImageBrushKey}"> <ContentPresenter /> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="border" Property="Background" Value="{StaticResource WhitePowerButtonImageBrushKey}" /> </Trigger> <Trigger Property="IsPressed" Value="True"> <Setter TargetName="border" Property="Background" Value="{StaticResource RedPowerButtonDrawingImageBrushKey}" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <Grid> <Button Style="{StaticResource PowerButtonStyleKey}" Margin="0 20 20 0" HorizontalAlignment="Center" VerticalAlignment="Center" Width="100" Height="100" /> </Grid> </Window> |