지금 이곳은 연봉 협상의 소용돌이가 몰아치고 있다. 난 아직 협상할 처지가 아니라 지켜보고 있지만
자기 스펙 관리 잘 해야 겠다는 것을 느꼈다. 무섭네..
WPF Label
C# 과 XAML 을 이용하여 WPF 에서 라벨 컨트롤을 어떻게 생성하는지 알아보자.
Creating a Label
XAML 에서 WPF Label 컨트롤은 Label 엘리먼트다.
< Label />
Label 엘리먼트의 Width 과 Height 어트리뷰트는 Label 의 너비와 높이를 나타낸다. Content 프로퍼티는 Label 의 텍스트를 나타낸다. Name 어트리뷰트는 Label 엘리먼트의 이름을 나타낸다. 즉, 컨트롤의 변수 이름이기 때문에 유일한 값을 갖어야 한다.
다음의 코드는 Label 컨트롤을 생성하고 Label 컨트롤의 이름, 높이, 너비, Content 를 설정한다. 또한 텍스트에 사용할 폰트 포멧을 설정한다.
<Label Name="Label1" Content="Hello! I am Label Control" Width="200" Height="40" Canvas.Left="10" Canvas.Top="10" FontSize="14" FontFamily="Georgia" FontWeight="Bold"/>

Background 와 Foreground 프로퍼티는 Label 컨트롤의 배경색과 전경색을 설정한다. VerticalAlignment 와 HorizontalAlignment 프로퍼티로 정렬을 설정한다.
<Label Name="Label1" Content="Hello! I am Label Control" Width="200" Height="30" Canvas.Left="10" Canvas.Top="10" FontSize="14" FontFamily="Georgia" FontWeight="Bold" Background="Black" Foreground="Orange" VerticalAlignment="Center" HorizontalAlignment="Center" />

Adding Contents to a Label Control
Label 컨트롤의 Content 프로퍼티는 다른 컨트롤로 채울 수 있다. 아래 코드는 Label 컨트롤의 Content 프로퍼티에 Ellipse 컨트롤로 채웠다. Content 프로퍼티에는 하나의 엘리먼트만 채울 수 있다. 따라서 아래는 StackPanel 을 Conent 프로퍼티에 연결 시키고, StackPanel 이 여러개의 엘리먼트를 갖게 하였다.
<Label Canvas.Left="10" Canvas.Top="50"> <StackPanel Orientation="Horizontal"> <Ellipse Width="100" Height="100" Fill="Red" /> <Ellipse Width="80" Height="80" Fill="Orange" /> <Ellipse Width="60" Height="60" Fill="Yellow" /> <Ellipse Width="40" Height="40" Fill="Green" /> <Ellipse Width="20" Height="20" Fill="Blue" /> <Ellipse Width="15" Height="15" Fill="Indigo" /> <Ellipse Width="10" Height="10" Fill="Violet" /> </StackPanel></Label>

Formatting a Label
BorderBrush 프로퍼티는 Label 의 경계선을 그리기 위한 브러쉬를 설정한다. 아래 코드는 빨간색과 파란색을 조합한 linear gradient 브러쉬를 사용하여 Label 의 경계선 브러쉬를 설정하였다.
<Label.BorderBrush> <LinearGradientBrush StartPoint="0,0" EndPoint="1,1" > <GradientStop Color="Blue" Offset="0" /> <GradientStop Color="Red" Offset="1.0" /> </LinearGradientBrush></Label.BorderBrush>
Background 와 Foreground 프로퍼티에 Label 의 경계선 브러쉬를 linear gradient 브러쉬로 설정할 수 있다.
<Label.Background> <LinearGradientBrush StartPoint="0,0" EndPoint="1,1" > <GradientStop Color="Blue" Offset="0.1" /> <GradientStop Color="Orange" Offset="0.25" /> <GradientStop Color="Green" Offset="0.75" /> <GradientStop Color="Black" Offset="1.0" /> </LinearGradientBrush></Label.Background><Label.Foreground> <LinearGradientBrush StartPoint="0,0" EndPoint="1,1" > <GradientStop Color="Orange" Offset="0.25" /> <GradientStop Color="Green" Offset="1.0" /> </LinearGradientBrush></Label.Foreground>

Setting Image as Background of a Label
Label 의 Background 에 색상 뿐만 아니라 이미지로 설정할 수 있다.
<Label.Background> <ImageBrush ImageSource="Garden.jpg" /></Label.Background>

댓글 없음:
댓글 쓰기