728x90
반응형
728x170
▶ ResourceDictionary.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:theme="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero">
<Style x:Key="ButtonFocusVisualStyleKey">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle
Margin="2"
StrokeThickness="1"
Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"
StrokeDashArray="1 2"
SnapsToDevicePixels="true" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<LinearGradientBrush x:Key="ButtonNormalBackgroundBrushKey"
StartPoint="0 0"
EndPoint="0 1">
<GradientStop Offset="0" Color="#f3f3f3" />
<GradientStop Offset="0.5" Color="#ebebeb" />
<GradientStop Offset="0.5" Color="#dddddd" />
<GradientStop Offset="1" Color="#cdcdcd" />
</LinearGradientBrush>
<SolidColorBrush x:Key="ButtonNormalBorderBrushKey" Color="#ff707070" />
<Style x:Key="ChromeButtonStyleKey" TargetType="{x:Type Button}">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorderBrushKey}" />
<Setter Property="Background" Value="{StaticResource ButtonNormalBackgroundBrushKey}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
<Setter Property="Padding" Value="1" />
<Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisualStyleKey}" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<theme:ButtonChrome Name="buttonChrome"
BorderBrush="{TemplateBinding BorderBrush}"
RoundCorners="False"
Background="{TemplateBinding Background}"
SnapsToDevicePixels="true"
RenderDefaulted="{TemplateBinding IsDefaulted}"
RenderMouseOver="{TemplateBinding IsMouseOver}"
RenderPressed="{TemplateBinding IsPressed}">
<ContentPresenter
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Margin="{TemplateBinding Padding}"
RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</theme:ButtonChrome>
<ControlTemplate.Triggers>
<Trigger Property="IsKeyboardFocused" Value="true">
<Setter
TargetName="buttonChrome"
Property="RenderDefaulted"
Value="true" />
</Trigger>
<Trigger Property="ToggleButton.IsChecked" Value="true">
<Setter
TargetName="buttonChrome"
Property="RenderPressed"
Value="true" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="#adadad" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
728x90
▶ MainApplication.xaml
<Application x:Class="TestProject.MainApplication"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ResourceDictionary.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
반응형
▶ 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="ButtonChrome 엘리먼트 사용하기"
Background="LightGray"
FontFamily="나눔고딕코딩"
FontSize="16">
<Grid>
<StackPanel
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Button
Width="200"
Height="30"
BorderBrush="Transparent"
Background="Transparent"
Content="일반 버튼" />
<Button
Style="{DynamicResource ChromeButtonStyleKey}"
Margin="0 10 0 0"
Width="200"
Height="30"
BorderBrush="Transparent"
Background="Transparent"
Content="크롬 버튼" />
</StackPanel>
</Grid>
</Window>
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] UIElement 클래스 : GotFocus/LostFocus 이벤트를 사용해 키보드 포커스 획득/상실시 처리하기 (0) | 2022.01.28 |
---|---|
[C#/WPF] WeakEventManager<TEventSource, TEventArgs> 클래스 : AddHandler 정적 메소드를 사용해 이벤트 핸들러 추가하기 (0) | 2022.01.28 |
[C#/WPF] EventManager 클래스 : RegisterClassHandler 정적 메소드를 사용해 특정 라우팅 이벤트에 대한 클래스 처리기 등록하기 (0) | 2022.01.27 |
[C#/WPF] ControlTemplate 엘리먼트 : Button 엘리먼트 정의하기 (0) | 2022.01.27 |
[C#/WPF] Decorator 엘리먼트 : 커스텀 버튼 크롬 만들기 (0) | 2022.01.27 |
[C#/WPF] 커스텀 포커스 범위 사용하기 (0) | 2022.01.27 |
[C#/WPF] Image 클래스 : 이미지 색상 선택기 사용하기 (0) | 2022.01.22 |
[C#/WPF] IValueConverter 인터페이스 : 색상→단색 브러시 변환자 사용하기 (0) | 2022.01.22 |
[C#/WPF] FrameworkElement 클래스 : ContextMenuOpening 이벤트를 사용해 컨텍스트 메뉴 표시 방지하기 (0) | 2022.01.19 |
[C#/WPF] FrameworkElement 클래스 : ContextMenuOpening 이벤트를 사용해 전체 컨텍스트 메뉴 항목 교체하기 (0) | 2022.01.19 |
댓글을 달아 주세요