XAML에서 태그는 반드시 끝맺음 태그를 사용하거나 시작 태그에 슬래시를 사용하여 닫아야한다.
<Button>
</Button>
<Button />
HTML은 대소문자를 구분하지 않지만 XAML에서 컨트롤의 이름 및 속성은 .NET Framework의 타입과 연관되어 있어야하기 때문에 구분한다.
<Button>
<Button.FontWeight>Bold</Button.FontWeight>
<Button.Content>New Button</Button.Content>
</Button>
<Button FontWeight="Bold"
Content="New Button">
</Button>
Content 속성은 하나의 하위 요소를 가질 수 있다.
예제에서는 WrapPanel을 사용한다.
일단 단순히 컨트롤러들을 담는 컨테이너라고 생각하자.
<Button>
<Button.FontWeight>Bold</Button.FontWeight>
<Button.Content>
<WrapPanel>
<TextBlock Foreground="Blue">Blue</TextBlock>
<TextBlock Foreground="Red">Red</TextBlock>
<TextBlock>Button</TextBlock>
</WrapPanel>
</Button.Content>
</Button>
<Button FontWeight="Bold">
<WrapPanel>
<TextBlock Foreground="Blue">Blue</TextBlock>
<TextBlock Foreground="Red">Red</TextBlock>
<TextBlock>Button</TextBlock>
</WrapPanel>
</Button>
CodeBehind란 말 그대로 뒤에서 코드로 작성하는 것을 의미한다.
XAML을 사용하지않고 C#코드로 작성할 수 있다.
Button btn = new Button();
btn.FontWeight = FontWeights.Bold;
WrapPanel pnl = new WrapPanel();
TextBlock txt = new TextBlock();
txt.Text = "Multi";
txt.Foreground = Brushes.Blue;
pnl.Children.Add(txt);
txt = new TextBlock();
txt.Text = "Color";
txt.Foreground = Brushes.Red;
pnl.Children.Add(txt);
txt = new TextBlock();
txt.Text = "Button";
pnl.Children.Add(txt);
btn.Content = pnl;
pnlMain.Children.Add(btn);