WPF스터디 2장

Download Report

Transcript WPF스터디 2장

XAML 신비를 벗다
발표자 : 최우진
[email protected]
[email protected]
▶ XAML의 필요성
▶ XAML의 정의
▶ 엘리먼트와 어트리뷰트
▶ 네임스페이스
▶ 프로퍼티 엘리먼트
▶ 타입컨버터
▶ 마크업 확장식
▶ 오브젝트 엘리먼트의 자식요소들
▶ XAML과 프로그래밍 코드를 함께 고고싱
▶ 정리
▶Q&A
XAML의 필요성
 사용자 인터페이스 혹은 객체 간의 계층구조를 간결하
게 표현하는데 적합
 디자인과 개발을 분리할 수 있기 때문에 유지보수 측
면에서 상당히 유용
 윈도우 SDK에 포함되어 있는 XamlPad 같은 프로그램
으로 컴파일하지 않고도 결과를 즉시 확인할 수 있다.
 WPF로 작성된 대부분의 프로그램에서 사용된다.
XAML의 정의
 닷넷의 객체들을 초기화하거나 생성하기에 적합하도
록 설계된 간편하고 범용적인 선언형 프로그래밍 언어
 닷넷 프레임워크 3.0은 컴파일러와 XAML 실행 파서,
익스플로러 내에서 WPF기반 XAML파일을 독립적으
로 실행시킬 수 있는 플러그인 포함
엘리먼트와 어트리뷰트
XAML:
<Button xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Content="OK"
Click="button_Click"/>
Content="OK"/>
C#:
C#:
System.Windows.Controls.Button
System.Windows.Controls.Button b
b=
= new
new System.Windows.Controls.Button();
System.Windows.Controls.Button();
b.Click += new System.Windows.RoutedEventHandler(button_Click);
b.Content = "OK";
b.Content = "OK";
네임스페이스
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation
"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 <WpfNamespace:Button xmlns:WpfNamespace=
 "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 Content="OK"/>
프로퍼티 엘리먼트
System.Windows.Controls.Button
b = new System.Windows.Controls.Button();
<Button
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
System.Windows.Shapes.Rectangle r = new System.Windows.Shapes.Rectangle();
<Button.Content>
r.Width = 40;Height="40" Width="40" Fill="Black"/>
<Rectangle
r.Height = 40;
</Button.Content>
r.Fill = System.Windows.Media.Brushes.Black;
</Button>
b.Content = r; // Make the square the content of the Button
프로퍼티 엘리먼트
<Button xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Content="OK" Background="White"/>
<Button xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Button.Content>
OK
</Button.Content>
<Button.Background>
White
</Button.Background>
</Button>
타입컨버터



System.Windows.Controls.Button b = new System.Windows.
b.Content = "OK";
b.Background = System.Windows.Media.Brushes.White;






<Button xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation”
Content="OK">
<Button.Background>
<SolidColorBrush Color="White"/>
</Button.Background>
</Button>
<Button xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation”
Content="OK">
 <Button.Background>
 <SolidColorBrush>
 <SolidColorBrush.Color>
 <Color A="255" R="255" G="255" B="255"/>
 </SolidColorBrush.Color>
 </SolidColorBrush>
 </Button.Background>
 </Button>
마크업 확장식
 없음
오브젝트 엘리먼트의 자식요소들
 컨텐트 프로퍼티
 컬렉션 아이템
▷리스트
▷딕셔너리
 더 다양한 형변환
XAML과 프로그래밍 코드를 함께 고고
싱
 런타임 시에 XAML을 로드하고 파싱하기
▷ XamlReader
▷ XAML 엘리먼트에 이름 사용하기
 XAML 컴파일하기
XAML의 키워드
공부하세요 ^^;;
Q&A
Quiz
같은 크기의 버튼 모양 XAML 파일을 만들었을때
Button으로 작업을 한 것과 Rectangle로 작업을 한 것은
마우스 이벤트 효과에서 어떤 차이가 있을까요?
Ex) Button1.XXXXXX (O)
Button2.XXXXXX (O)
Button1.YYYYYY (O)
Button2.YYYYYY (X)