■ ControlTemplate 엘리먼트를 사용해 ToolTip 엘리먼트를 정의하는 방법을 보여준다.
▶ 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 |
<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="BorderMediumColorKey">#ff888888</Color> <Style x:Key="{x:Type ToolTip}" TargetType="ToolTip"> <Setter Property="OverridesDefaultStyle" Value="true" /> <Setter Property="HasDropShadow" Value="True" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ToolTip"> <Border Name="border" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" BorderThickness="1"> <Border.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> </Border.Background> <Border.BorderBrush> <SolidColorBrush Color="{DynamicResource BorderMediumColorKey}" /> </Border.BorderBrush> <ContentPresenter HorizontalAlignment="Left" VerticalAlignment="Top" Margin="4" /> </Border> <ControlTemplate.Triggers> <Trigger Property="HasDropShadow" Value="true"> <Setter TargetName="border" Property="CornerRadius" Value="4" /> <Setter TargetName="border" Property="SnapsToDevicePixels" Value="true" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <Button HorizontalAlignment="Center" VerticalAlignment="Center" Width="100" Height="30" Content="테스트"> <Button.ToolTip> <ToolTip> <Ellipse Margin="10" Width="100" Height="100" Fill="Yellow" /> </ToolTip> </Button.ToolTip> </Button> </Window> |