WPF์์ ๊ฐ์ฅ ๋ง์ด ์ฌ์ฉ๋๋ ์ปจํธ๋กค ์ค์ ํ๋์ธ Button์ ๊ดํ ์ฐ๊ตฌ๋ฅผ ์งํํฉ๋๋ค.
์ฐ๊ตฌ ํญ๋ชฉ
- ๋ฒํผ(Button) ์ฌ๋ก
- Button Class
- Template
- Geometry
- Trigger
- DataContext
- DependencyProperty
๋ชฉํ: (์๋๋ ๋๋์ง๋ง) ์ค๋ช
๊ณผ ์์ค์ฝ๋๋ฅผ ์์ธํ๊ฒ ์ ๋ฆฌํ๊ณ WPF Button ๊ด๋ จ ์ ๋ณด๋ค์ ์ ๊ฒ์ฆ๊ณ ์ง์์ ์ผ๋ก ๊ด๋ฆฌํด ๋๊ฐ๋ ๊ฒ์ ๋ชฉ์ ์ ๋๊ณ ์์ต๋๋ค. 
4๊ฐ์ ์ข์์
๋ค์ํ ํ๋ก๊ทธ๋จ์์์ ๋ฒํผ(Button)
GitHub Repository ์์ฑ ๋ฒํผ

๋ท๋ท๋ฐ๋ธ ํ ํฝ ๋ง๋ค๊ธฐ ๋ฒํผ

์นด์นด์คํก ์ฑํ
์ฐฝ ์ ์ก ๋ฒํผ

๋ฆฌ๊ทธ์ค๋ธ๋ ์ ๋ ์๋ด ๊ฐ์ด๋ ๋ฒํผ

Button Class (๋ฒํผ ํด๋์ค)
์ด๋ฆ |
UI ํ์
|
๋ค์์คํ์ด์ค |
์ด์
๋ธ๋ฆฌ |
Button |
ContentControl |
System.Windows.Controls |
PresentationFramework.dll |
WPF ๋ฒํผ์ Content ์์ฑ์ ํฌํจํ๋ ContentControl ๊ธฐ๋ฐ์ ํด๋์ค์
๋๋ค. ContentControl์ ๊ธฐ๋ฐ์ผ๋ก ํ๋ ํด๋์ค๋ Button ๋ง๊ณ ๋ Window, UserControl, CheckBox, ToggleButton, Expander ๋ฑ์ด ์์ต๋๋ค.
Button ํด๋์ค์ ๊ฐ์ฅ ํฐ ํน์ง์ ContentTemplate์ ํธ์งํ ์ ์๋ค๋ ์ ๊ณผ Click ์ด๋ฒคํธ๋ฅผ ํฌํจํ Button ๋์์ ๊ด๋ จ๋ Event๋ฅผ ์ฌ์ฉํ ์ ์๋ค๋ ์ ์
๋๋ค. ๋ํ ๋ค๋ฅธ UI ํด๋์ค๋ค๊ณผ ๋ฌ๋ฆฌ Command๋ผ๋ ICommand ํ์
์ ์์ฑ(DependencyProperty)๋ฅผ ํตํด Click ์ด๋ฒคํธ๋ฅผ Binding์ ํตํด ์ฐ๊ฒฐํ ์๋ ์์ต๋๋ค. ์ด๋ Button ๋ด๋ถ์ ์ผ๋ก ๋ฒํผ ํด๋ฆญ ์ Command๋ฅผ ?.Invoke() ํ๋๋ก ์ค๊ณ๋์ด ์๊ธฐ ๋๋ฌธ์
๋๋ค.
๊ธฐ๋ณธ ์คํ์ผ ํํ
<Style TargetType="{x:Type Button}">
<Setter>
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border>
<!-- TBD... -->
<ContentPresenter/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Button๊ณผ ๊ฑฐ์(99%) ๋์ผํ DNA
ContentControl์ ๊ธฐ๋ฐ์ผ๋ก ํ ๋ชจ๋ ์ปจํธ๋กค์ด ๋์์
๋๋ค.
- ToggleButton
- CheckBox
- RadioButton
- Window
- UserControl
TBDโฆ
2๊ฐ์ ์ข์์
๋ฒํผ Template ์์
- ๊นํ๋ธ ๋ฒํผ
- ๋ท๋ท๋ฐ๋ธ ๋ฒํผ
- ์นด์นด์คํก ๋ฒํผ
- ๋ฆฌ๊ทธ์ค๋ธ๋ ์ ๋ ๋ฒํผ
๋ค์ด๋ก๋
GitHub ์์ค์ฝ๋
๊นํ๋ธ ๋ฒํผ
๊ธฐ๋ณธ ์ํ (Default)

์์ ํ (HEX)
BorderBrush #2B9148
Background #2EA44F
Foreground #FFFFFF
Fill #FFFFFF
Background.IsMouseOver #2c974b
์์ด์ฝ (Geometry)
<Geometry x:key="ICON">M8,8V6H10V8H8M7,2H17A2,2 0 0,1 19,4V19A2,2 0 0,1 17,21V22H15V21H9V22H7V21A2,2 0 0,1 5,19V4A2,2 0 0,1 7,2M7,4V9H17V4H7M8,12V15H10V12H8Z</Geometry>
์คํ์ผ (ControlTemplate)
<!-- Geometry Path Icon (.SVG) -->
<Geometry x:Key="ICON">M8,8V6H10V8H...</Geometry>
<!-- GitHub Button Style -->
<Style TargetType="{x:Type local:GitHubButton}">
<Setter Property="UseLayoutRounding" Value="True"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="Foreground" Value="#FFFFFF"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Margin" Value="5"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:GitHubButton}">
<ControlTemplate.Resources>
<Style TargetType="{x:Type Border}" x:Key="IN.BORDER">
<Setter Property="BorderBrush" Value="#2B9148"/>
<Setter Property="BorderThickness" Value="1 1 1 1"/>
<Setter Property="Background" Value="#2B9148"/>
<Setter Property="CornerRadius" Value="5"/>
</Style>
<Style TargetType="{x:Type StackPanel}" x:Key="IN.PANEL">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Orientation" Value="Horizontal"/>
</Style>
<Style TargetType="{x:Type Viewbox}" x:Key="IN.VBOX">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Margin" Value="12 0 4 0"/>
<Setter Property="Width" Value="16"/>
<Setter Property="Height" Value="16"/>
</Style>
<Style TargetType="{x:Type Path}" x:Key="IN.PATH">
<Setter Property="Data" Value="{StaticResource ICON}"/>
<Setter Property="Width" Value="24"/>
<Setter Property="Height" Value="24"/>
<Setter Property="Fill" Value="#FFFFFF"/>
</Style>
<Style TargetType="{x:Type ContentPresenter}" x:Key="IN">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Margin" Value="0 6 12 6"/>
</Style>
</ControlTemplate.Resources>
<Border Style="{StaticResource IN.BORDER}">
<StackPanel Style="{StaticResource IN.PANEL}">
<Viewbox Style="{StaticResource IN.VBOX}">
<Path Style="{StaticResource IN.PATH}"/>
</Viewbox>
<ContentPresenter Style="{StaticResource IN}"/>
</StackPanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
ControlTemplate ์์ญ ํ์ ์ปจํธ๋กค ์คํ์ผ
x:Key |
TargetType |
Remark |
IN.BORDER |
Border |
CornerRadius=โ5 5 5 5โ |
IN.PANEL |
StackPanel |
Orientation=โHorizontalโ |
IN.VBOX |
ViewBox |
W16 x H16 |
IN.PATH |
Path |
W24 x H24 (์ค์ .svg size) |
IN |
ContentPresenter |
ContentSource=โContentโ |
|
|
|
WPF ์คํ ๊ฒฐ๊ณผ
TBDโฆ

GitHub ์์ค์ฝ๋
TBDโฆ
2๊ฐ์ ์ข์์