반응형
얼리먼트 간의 포함 관계
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Programming .Net 3.5" >
<StackPanel Height="200">
<Button Width="200" VerticalAlignment="Center">
<StackPanel Orientation="Horizontal">
<Canvas Width="300" Height="30" VerticalAlignment="Center" Margin="3">
<Ellipse Canvas.Left="1" Canvas.Top="1" Width="30" Height="30" Fill="White" Stroke="Black" />
<Ellipse Canvas.Left="4" Canvas.Top="4" Width="24" Height="24" Fill="Black" />
<Ellipse Canvas.Left="8" Canvas.Top="8" Width="16" Height="16" Fill="Blue" Stroke="Blue" />
<Ellipse Canvas.Left="11" Canvas.Top="11" Width="10" Height="10" Fill="Red" Stroke="Red" />
<Ellipse Canvas.Left="14" Canvas.Top="14" Width="4" Height="4" Fill="Yellow" Stroke="Yellow" />
<TextBlock Canvas.Left="60" Canvas.Bottom="10" VerticalAlignment="Center">Ready, Fire, Aim!</TextBlock>
</Canvas>
</StackPanel>
</Button>
</StackPanel>
</Window>
리소스(Window.Resource)
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Window.Resources >
<SolidColorBrush x:Key="GreenBrush" Color="Green" />
</Window.Resources>
<Viewbox>
<TextBlock Foreground="{DynamicResource GreenBrush}">Little Green Men</TextBlock>
</Viewbox>
</Window>
리소스는 XAML에서 사용할 오브젝트를 정의하고 공유할 수 있게 해준다. 리소스를 공유할 수 있는 범위는 일반적으로 Page 혹은 Window 수준에서 사용하지만, 전체 프로그램이나 심지어는 전체 시스템 차원에서 공유할 수 있다.
XMAL의 Resources 섹션은 가끔 "리소스 딕셔너리(resource dictionary)"로서 참조된다
이 리소스는 TextBlock 의 Foreground 프로퍼티에 리소스 자체를 값으로 넘겨주면 적용된다. 이때 StaticResourced 키워드를 사용하면 이 리소스는 컴파일 타임에 설정되고 런타임 시에는 수정할 수 없다.
반대로, DynamicResource는 런타임 시에 정의된다 스킨으로 사용할 수 있는 프로퍼티들은 모두 DynamicResource로 참조하게 되면, 다른 리소스 딕셔너리로 바꾸기만 해도 프로그램의 스킨을 변경할 수 잇다. 실제로, WPF는 그러한 처리가 이루어지면 해당하는 모든 프로퍼티를 자동으로 수정한다.
형태변형
2D 그래픽에서 다룰 내용이 많긴 하지만, 그중에서도눈에 띄는 기능 중 하나는 컨트롤이 가지고 있는
모양을 바꿀 수 있는 형태 변형 (Transformation)이다,
이기서, 페이지의 위아래 방향으로 컨트롤의 방향이 달라지는 예를 살펴볼 것이다
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="타이틀">
<Border Margin="30" HorizontalAlignment="Left" VerticalAlignment="Top" BorderBrush="Black" BorderThickness="1">
<StackPanel Orientation="Vertical">
<Button Content="Top Button" Opacity="1" />
<Button Content="Middle Button" Opacity="1" />
<Button Content="Rotated Button">
<Button.RenderTransform>
<RotateTransform Angle="45" />
</Button.RenderTransform>
</Button>
</StackPanel>
</Border>
</Window>
세 번째 Button 은 RenderTransform을 가지고 있고, 이 프로퍼티는 회전 각도를 조절할 수 있는 RotateTransform 을 자식 엘리먼트로 사용했다. 세번째 버튼은 45도 시계 방향으로 회전한채 렌더링된다
- 참고 Programming .Net 3.5 by Jesse Liberty and Alex Horovitz.
'.NET > WPF' 카테고리의 다른 글
WPF 기초 리스트에 바인딩하기 (0) | 2009.07.20 |
---|---|
WPF 기초 데이터 바인딩 (0) | 2009.07.18 |
WPF 기초 복합 컨트롤 (0) | 2009.07.17 |
WPF 기초 의존 프로퍼티와 첨부 프로퍼티 애니메이션, 동시 실행 애니메이션 (0) | 2009.07.17 |
WPF 기초 Resource, Linear Gradient , Style (0) | 2009.07.16 |
WPF 기초 <Viewbox><Canvas> <Path> (0) | 2009.07.15 |
WPF 기초 StackPanel 사용과 <FlowDocumentReader> <FlowDocument> <Paragraph> <Paragraph.FontFamily> <Paragraph.FontSize> <Bold> <LineBreak /> (0) | 2009.07.15 |
WPF 기초 DockPanel 선언 순서가 중요하다 (0) | 2009.07.15 |