<StackPanel.Resources> <!--StackPanel내에서만 사용하는 Resource-->

<!--모든버튼에 편하게 일괄적용 but 버튼구별은 못함-->

<Style TargetType="{x:Type Button}">

<Setter Property="Button.Margin" Value="3,3"/>

<Setter Property="Button.Background" Value="yellow"/>

<Setter Property="Button.RenderTransformOrigin" Value="0.5, 0.5"/>

<Setter Property="Button.RenderTransform">

<Setter.Value>

<RotateTransform Angle="20" />

</Setter.Value>

</Setter>

</Style>

<Style x:Key="redStyle">

<Setter Property="Button.Margin" Value="3,3"/>

<Setter Property="Button.Background" Value="red"/>

</Style>

</StackPanel.Resources>

<Button >버튼</Button>

<Button>버튼</Button>

<!--역시나 적은 범위의 Style 적용됨-->

<Button Style="{StaticResource redStyle}">버튼</Button>

<Button>버튼</Button>

<Button>버튼</Button>

 


by 피요히코~ 2009. 2. 25. 12:57

style

 - 리소스와 비슷/ 리소스 모음(?)

<!--Style-->

<Window.Resources>

<Style x:Key="userStyle"> <!--resource이기 때문에 name 아니라 key 사용-->

<Setter Property="Control.FontSize" Value="30" />  <!--Property="자료형.지정속성" value="속성값"-->

<Setter Property="Control.FontFamily" Value="궁서" />

<Setter Property="Control.Background" Value="Black" />

<Setter Property="Control.Foreground" Value="White" />

</Style>

<SolidColorBrush x:Key="redBrush" Color="Red"/>

</Window.Resources>

 

<StackPanel>

<!--스타일-->

<Button Margin="3,3" Style="{StaticResource userStyle}">버튼1</Button> <!--{} << 확장프로퍼티-->

<Button Margin="3,3" Style="{StaticResource userStyle}">버튼2</Button>

 <!-- 적은 범위의 속성값으로 적용됨(버튼3)->

<Button Margin="3,3" Style="{StaticResource userStyle}" Background="{StaticResource redBrush}">버튼3</Button>

<!--TextBox Label에도 적용됨-->

<TextBox Style="{StaticResource userStyle}">텍스트박스입니다.</TextBox>

<!--화면내 많은 컨트롤들의 속성을 통일시켜줄때 많이 사용-->

<Label Style="{StaticResource userStyle}">문자열입니다</Label>

</StackPanel>

 

*버튼3만 다르게 표시


by 피요히코~ 2009. 2. 25. 12:56

파일내에서 참조

<Window.Resources>

<!--Window내에서 모두 사용가능-->

<SolidColorBrush x:Key="yellowBrush" Color="Yellow"/>

</Window.Resources>

<StackPanel>

<!--확장프로퍼티{}-->

<!--실제코드는 전과 차이가 없지만. 일괄수정시 편하다-->

<Button Margin="5,5" Background="{StaticResource yellowBrush}">버튼</Button><Button Margin="5,5" Background="{StaticResource yellowBrush}">버튼</Button>

</StackPanel>

 

프로젝트(?) 전체에서 참조 - ResourceDitionary 사용

 

-ResourceDictionary

 

<--프로젝트 솔루션에서 /추가 - 리소스사전/  (Dictionary1.xaml) -->

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<SolidColorBrush x:Key="testBrush" Color="Red"/><!--단일자원 리소스-->

</ResourceDictionary>

-사용

 

 

<Window.Resources>

<ResourceDictionary Source="Dictionary1.xaml"/><!--리소스사전 참조-->

</Window.Resources>

<StackPanel>

<!--사용방법은 똑같다-->

<Button Background="{StaticResource testBrush}">버튼1</Button>

<Button Background="{StaticResource testBrush}">버튼2</Button>

<Button Background="{StaticResource testBrush}">버튼3</Button>

</StackPanel>



by 피요히코~ 2009. 2. 25. 12:55