xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Style01" Height="300" Width="300">
<Window.Resources>
<!--스타일 리소스 : 속성과 속성값의 집합-->
<!--1. x:Key를 사용해서 지정 CSS의 클래스 선택자와 유사-->
<!--<Style x:Key="btnStyle">
<Setter Property="Button.Width" Value="100" />
<Setter Property="Button.Height" Value="30" />
<Setter Property="Button.Margin" Value="5" />
<Setter Property="Button.Background" Value="Blue" />
</Style>-->
<!--2. x:Type을 사용해서 지정-->
<!--세밀한 그림-->
<!--<Style TargetType="{x:Type Button}">
<Setter Property="Width" Value="150" />
<Setter Property="Height" Value="50" />
<Setter Property="Margin" Value="5" />
<Setter Property="Background" Value="Yellow" />
</Style>-->
<!--3. 1번 + 2번 합치기-->
<Style x:Key="btnStyle" TargetType="{x:Type Button}">
<Setter Property="Width" Value="150" />
<Setter Property="Height" Value="50" />
<Setter Property="Margin" Value="5" />
<Setter Property="Background" Value="Yellow" />
</Style>
</Window.Resources>
<StackPanel>
<!--<Button Content="버튼" Background="Yellow" Width="150" Height="50" Margin="5" />-->
<!-- {} : 확장 속성-->
<!--<Button Content="버튼" Style="{StaticResource btnStyle}" />
<Button Content="버튼" Style="{StaticResource btnStyle}" />
<Button Content="버튼" Style="{StaticResource btnStyle}" />-->
<!--2. x:Type을 사용해서 지정 => CSS의 태그 선택자
광범위 하며, 일괄 적용 (바탕그림)
-->
<Button Content="버튼" Style="{StaticResource btnStyle}"/>
<Button Content="버튼" />
<Button Content="버튼" />
</StackPanel>
</Window>
<!--
변형(Transform) 객체
1. 회전
2. 배율
3. 위치
4. 비틀기
적용 방법
1. 변형의 형태를 지정(위의 4가지중 1가지 선택)
2. 변형의 중심 축 지정(절대값, 상대값)
3. 변형 적용
-->
<Window x:Class="WPFEx.Transform"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Transform" Height="300" Width="300">
<StackPanel>
<Button Content="버튼" Width="50" Height="50" Margin="5" RenderTransformOrigin="0.5,0.5">
<Button.RenderTransform>
<RotateTransform Angle="30" />
</Button.RenderTransform>
</Button>
<Button Content="버튼" Width="50" Height="50" Margin="5" RenderTransformOrigin="0,0">
<Button.RenderTransform>
<RotateTransform Angle="30" />
</Button.RenderTransform>
</Button>
<Button Content="버튼" Width="50" Height="50" Margin="5" RenderTransformOrigin="1,1">
<Button.RenderTransform>
<RotateTransform Angle="10" CenterX="0" CenterY="0"/>
</Button.RenderTransform>
</Button>
<!--중심 축을 외부에 놓는다 축의 기준에 따라 버튼에 움직임을 다양하게 변경 할수 있다.-->
<Button Content="버튼" Width="50" Height="50" Margin="5" RenderTransformOrigin="1,1">
<Button.RenderTransform>
<RotateTransform Angle="30" CenterX="100" CenterY="100"/>
</Button.RenderTransform>
</Button>
</StackPanel>
</Window>
<!--변형 객체 스타일로 빼서 핸들링-->
<Window x:Class="WPFEx.TransForm02"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="TransForm02" Height="500" Width="500">
<Window.Resources>
<!--2. 스타일 리소스-->
<Style x:Key="btnStyle" TargetType="{x:Type Button}">
<Setter Property="Width" Value="100" />
<Setter Property="Height" Value="50" />
<Setter Property="Margin" Value="5" />
<Setter Property="RenderTransformOrigin" Value="0.5,0.5" />
<Setter Property="RenderTransform">
<Setter.Value>
<RotateTransform Angle="30" />
</Setter.Value>
</Setter>
</Style>
<!--1. 객체 리소스-->
<RotateTransform x:Key="rt1" Angle="45" />
</Window.Resources>
<StackPanel>
<Button Content="버튼" Width="100" Height="50" Margin="5" RenderTransformOrigin="0.5,0.5">
<Button.RenderTransform>
<RotateTransform Angle="30" />
</Button.RenderTransform>
</Button>
<Button Content="버튼1" Style="{StaticResource btnStyle}" />
<Button Content="버튼2" Style="{StaticResource btnStyle}" />
<Button Content="버튼3" Style="{StaticResource btnStyle}" />
<Button Content="버튼4" Width="100" Height="100" RenderTransformOrigin="0.5,0.5" RenderTransform="{StaticResource rt1}" />
</StackPanel>
</Window>
-
<Window x:Class="WPFEx.TransForm03"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="TransForm03" Height="300" Width="300">
<StackPanel>
<ScrollBar Name="scroll1" Minimum="-1" Maximum="1" Orientation="Horizontal"Value="1" />
<Button Content="버튼" Width="100" Height="50" Margin="5"RenderTransformOrigin="0.5,0.5">
<Button.RenderTransform>
<!--확대-->
<!--<ScaleTransform ScaleX="2" ScaleY="2" />-->
<!--축소 거울에 비친거와 같이 뒤집어진다.-->
<ScaleTransform ScaleX="1" ScaleY="{BindingElementName=scroll1, Path=Value}" />
</Button.RenderTransform>
</Button>
<ScrollBar Name="scroll2" Minimum="-200" Maximum="200"Orientation="Horizontal" Value="1" />
<Button Content="버튼" Width="100" Height="50" Margin="5"RenderTransformOrigin="0.5,0.5">
<Button.RenderTransform>
<!--
객체의 좌표 지정
1. Canvas의 자식 지정 => Left, Top등
2. Canvas의 자식X => Margin 사용
3. TranslateTransform 사용(본인 기준)
-->
<TranslateTransform X="{Binding ElementName=scroll2,Path=Value}" Y="{Binding ElementName=scroll2, Path=Value}" />
</Button.RenderTransform>
</Button>
<ScrollBar Name="scroll3" Minimum="-200" Maximum="200"Orientation="Horizontal" Value="1" />
<Button Content="버튼" Width="100" Height="50" Margin="5"RenderTransformOrigin="0.5,0.5">
<Button.RenderTransform>
<SkewTransform AngleX="{Binding ElementName=scroll3,Path=Value}" AngleY="0" />
</Button.RenderTransform>
</Button>
</StackPanel>
</Window>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="LayoutTransform" Height="300" Width="300">
<Window.Resources>
<Style x:Key="btnStyle" TargetType="{x:Type Button}">
<Setter Property="Width" Value="80" />
<Setter Property="Height" Value="80" />
<Setter Property="Margin" Value="5" />
<Setter Property="RenderTransformOrigin" Value="0.5,0.5" />
<Setter Property="LayoutTransform">
<Setter.Value>
<RotateTransform Angle="45" />
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<StackPanel>
<Button Content="버튼" Style="{StaticResource btnStyle}" />
<Button Content="버튼" Style="{StaticResource btnStyle}" />
<Button Content="버튼" Style="{StaticResource btnStyle}" />
</StackPanel>
</Window>
Trigger
<!--
트리거(Trigger) : 방아쇠, 이벤트와 유사
사건 발생 : 미리 준비해놓은 무언가 실행
사건 발생 : 미리 준비해놓은 스타일을 적용
-->
<Window x:Class="WPFEx.Trigger"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Trigger" Height="300" Width="300">
<!--<Button Content="버튼" Width="100" Height="100">
<Button.Triggers>
<Trigger Property="Button.IsMouseOver" Value="True">
<Setter Property="Button.Width" Value="150" />
<Setter Property="Button.Height" Value="150" />
</Trigger>
</Button.Triggers>
</Button>-->
<StackPanel>
<StackPanel.Resources>
<Style x:Key="btnStyle" TargetType="{x:Type Button}">
<Setter Property="Width" Value="80" />
<Setter Property="Height" Value="50" />
<Setter Property="Margin" Value="5" />
<Setter Property="RenderTransformOrigin" Value="0.5,0.5" />
<Style.Triggers>
<!--속성 트리거-->
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Width" Value="150" />
<Setter Property="Height" Value="100" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="RenderTransform">
<Setter.Value>
<RotateTransform Angle="30" />
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</StackPanel.Resources>
<Button Content="버튼1" Style="{StaticResource btnStyle}" />
<Button Content="버튼2" Style="{StaticResource btnStyle}" />
<Button Content="버튼3" Style="{StaticResource btnStyle}" />
</StackPanel>
</Window>
<Window x:Class="WPFEx.Trigger02"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Trigger02" Height="300" Width="300">
<Window.Resources>
<Style x:Key="circle" TargetType="{x:Type Ellipse}">
<Setter Property="Width" Value="120" />
<Setter Property="Height" Value="120" />
<Setter Property="Stroke" Value="Red" />
<Setter Property="StrokeThickness" Value="10" />
<Setter Property="Fill" Value="Yellow" />
<Setter Property="Margin" Value="5" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<!--<Setter Property="Fill" Value="Blue" />-->
<Setter Property="Width" Value="100" />
<Setter Property="Height" Value="100" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<StackPanel>
<Ellipse Style="{StaticResource circle}" />
<Ellipse Style="{StaticResource circle}" />
</StackPanel>
</Window>
Template
<Window x:Class="WpfEx.Ex23_Template"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Ex23_Template" Height="300" Width="300">
<Window.Resources>
<!--템플릿 : 적용시킬 객체(컨트롤)의 모양 선언-->
<ControlTemplate x:Key="btnTemplate" TargetType="{x:Type Button}">
<!--이곳에 선언되는 모든 내용이 버튼의 외관이 된다.-->
<Ellipse Stroke="Red" Fill="Yellow" Width="50" Height="50" StrokeThickness="5" />
</ControlTemplate>
</Window.Resources>
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Content="버튼" Width="100" Height="100" Click="Button_Click" Template="{StaticResource btnTemplate}"/>
</Grid>
</Window>
<Window x:Class="WpfEx.Ex24_Template"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Ex24_Template" Height="300" Width="300">
<Window.Resources>
<ControlTemplate x:Key="switch" TargetType="{x:Type CheckBox}">
<Grid ShowGridLines="False">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.Children>
<Border Width="96" Height="48" BorderBrush="Black" BorderThickness="1" Grid.Row="0" Grid.Column="0">
<Canvas Background="LightGray">
<Line X1="48" Y1="40" X2="20" Y2="16" Stroke="Black" StrokeThickness="8" Name="lineOff" />
<Line X1="48" Y1="40" X2="76" Y2="16" Stroke="Black" StrokeThickness="8" Name="lineOn" Visibility="Hidden" />
<TextBlock Text="Off" Foreground="Black" Margin="2" Name="txtOff" />
<TextBlock Text="On" Foreground="Black" Margin="2" Name="txtOn" Visibility="Hidden" />
</Canvas>
</Border>
<ContentPresenter Grid.Row="1" Grid.Column="0" HorizontalAlignment="Center" Margin="5" Content="{TemplateBinding Content}" />
</Grid.Children>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Visibility" Value="Hidden" TargetName="lineOff" />
<Setter Property="Visibility" Value="Hidden" TargetName="txtOff" />
<Setter Property="Visibility" Value="Visible" TargetName="lineOn" />
<Setter Property="Visibility" Value="Visible" TargetName="txtOn" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Window.Resources>
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<CheckBox Content="보일러 전원" Template="{StaticResource switch}" />
</Grid>
</Window>