[C#/WPF] ControlTemplate 엘리먼트 : RelativeSource 태그 확장에서 TemplatedParent 모드 사용하기
C#/WPF 2014. 1. 31. 01:54728x90
반응형
728x170
■ ControlTemplate 엘리먼트에서 RelativeSource 태그 확장의 TemplatedParent 속성을 사용하는 방법을 보여준다.
▶ MainWindow.xaml
<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="ControlTemplate 엘리먼트 : RelativeSource 태그 확장에서 TemplatedParent 모드 사용하기"
FontFamily="나눔고딕코딩"
FontSize="16">
<Window.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border x:Name="border"
BorderThickness="2"
BorderBrush="Black"
CornerRadius="20">
<Border.Background>
<LinearGradientBrush
StartPoint="0 0.5"
EndPoint="1 0.5">
<GradientStop
Offset="0.0"
Color="{Binding Background.Color, RelativeSource={RelativeSource TemplatedParent}}" />
<GradientStop Offset="0.9" Color="White" />
</LinearGradientBrush>
</Border.Background>
<ContentPresenter
Margin="2"
HorizontalAlignment="Center"
VerticalAlignment="Center"
RecognizesAccessKey="True" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background">
<Setter.Value>
<LinearGradientBrush
StartPoint="0 0.5"
EndPoint="1 0.5">
<GradientStop
Offset="0.0"
Color="{Binding Background.Color, RelativeSource={RelativeSource TemplatedParent}}" />
<GradientStop Offset="0.9" Color="DarkSlateGray" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<Button
Width="300"
Height="300"
Background="RoyalBlue"
FontWeight="Bold"
FontSize="18">
<TextBlock FontSize="48">
테스트
</TextBlock>
</Button>
</Grid>
</Window>
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] FormatConvertedBitmap 엘리먼트 : DestinationFormat 속성을 사용해 비트맵 픽셀 포맷 변경하기 (0) | 2014.01.31 |
---|---|
[C#/WPF] BitmapImage 클래스 : 크기 조정 비트맵 이미지 구하기 (0) | 2014.01.31 |
[C#/WPF] BitmapImage 엘리먼트 : DecodePixelWidth/DecodePixelHeight 속성 사용하기 (0) | 2014.01.31 |
[C#/WPF] Image 엘리먼트 : Width 속성 사용하기 (0) | 2014.01.31 |
[C#/WPF] Storyboard 클래스 : 코드 구현하기 (0) | 2014.01.31 |
[C#/WPF] WPF 버전 번호가 저장된 레지스트리 키 (0) | 2014.01.30 |
[C#/WPF] BrowserInteropHelper 클래스 : HostScript 속성을 사용해 XBAP 호스트 웹 페이지 통신하기 (0) | 2014.01.30 |
[C#/WPF] Button 클래스 : SetResourceReference 메소드를 사용해 리소스 설정하기 (0) | 2014.01.30 |
[C#/WPF] FrameworkElement 클래스 : TryFindResource 메소드를 사용해 리소스 찾기 (0) | 2014.01.30 |
[C#/WPF] FrameworkElement 클래스 : FindResource 메소드를 사용해 리소스 찾기 (0) | 2014.01.30 |
댓글을 달아 주세요