본문 바로가기
Windows/C#/WPF

WPF XAML 스타일 정의 예제

by hirudev 2021. 4. 29.
<Window x:Class="WpfApplication4.MainWindow" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        Title="MainWindow" Height="350" Width="525"> 
    <Window.Resources> 
        <!-- 스타일을 리소스에 정의함 --> 
        <Style TargetType="{x:Type Button}"> 
            <Setter Property="Background" Value="Black" /> 
            <Setter Property="Foreground" Value="White" /> 
        </Style> 
    </Window.Resources> 
    <StackPanel> 
        <!-- 화면에 버튼을 여러개 둠 --> 
        <Button Content="스타일 예제 01" /> 
        <Button Content="스타일 예제 02" /> 
        <Button Content="스타일 예제 03" /> 
        <Button Content="스타일 예제 04" /> 
        <Button Content="스타일 예제 05" /> 
    </StackPanel> 
</Window> 

TargetType 에서의 x:Type [리소스명] 에서 정의 후

 

정의된 '리소스명' 의 하기(下記)로 작성되는 인스턴스에 대해서 적용되는 예제이다.

( CSS 와 비슷해보인다. )

'Windows > C#/WPF' 카테고리의 다른 글

Object 요소 property  (0) 2021.05.01
XAML 의 로드  (0) 2021.04.30
WPF 의 구성  (0) 2021.04.28
C# Framework 프로젝트에서 WPF 사용하는 예제  (0) 2021.04.28
App.g.cs 를 보는 방법  (0) 2021.04.27

댓글