728x90
반응형
WPF & C# - Style 스타일 적용하기 ( Setter / Window.Resources ) |
TestStyle.zip
0.04MB
TestStyle.exe
0.01MB
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
|
<Window x:Class="TestStyle.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:TestStyle"
mc:Ignorable="d"
Title="MainWindow" Height="294.231" Width="420.562">
<Window.Resources>
<Style TargetType="{x:Type Button}" x:Key="btn">
<Setter Property="Width" Value="100"></Setter>
<Setter Property="Height" Value="100"></Setter>
<Setter Property="Background" Value="Blue"></Setter>
</Style>
</Window.Resources>
<Grid>
<StackPanel>
<Button x:Name="btn01" Style="{StaticResource btn}"></Button>
<Button x:Name="btn02" Style="{StaticResource btn}" Height="50" Background="Aqua"></Button>
<Button x:Name="btn03" Style="{StaticResource btn}"></Button>
</StackPanel>
</Grid>
</Window>
|
cs |
스타일 적용을 하면 디자인적으로 상당히 편리하다.
템플릿등을 만들어 놓고 사용할 수 있으니 한번만 고생해서 만들어 놓으면 좋을 듯 하다.
728x90
반응형