검색결과 리스트
2010/01/06 에 해당되는 글 2건
- 2010.01.06 First Look Silverlight 4]RichTextArea Part 1 (1)
- 2010.01.06 UX Bakery PDC 다시보기 Day1 [5/5]
1.RichTextArea Part 1
2.RichTextArea Part 2
3.Accessing Web Camera and Microphone
4.Right Click Mouse Events
5.MouseWheel API
6.Using Silveright Controls As Drop Targets
7.DataGrid Enhancements
8.Printing API Basics
9.Hosting HTML Content
10.Accessing the Global Clipboard Programmatically
11.Using the ViewBox Control
12.Asynchronous Data Validation
13.BiDi and Right-to-Left Support
14.Notification API
15.Local File Access
16.RIA Services support in Visual Studio 2010
| 김영욱 차장 Microsoft Korea .NET Evangelist Enterprise UX 를 위한 UI 기술과 SOA, Cloud Computing, NUI등 다양한 분야의 접목과 응용을 통해 최적의 IT 인프라 구축을 위해서 노력하고 있다. Email: iwinkey@hotmail.com Blog: http://winkey.tistory.com |
첫 번째 강좌를 시작하기 전에 먼저 몇 가지 체크해야 하는 것 들입니다. 우선 개발 툴과 디자인 툴에 관해서 입니다.
Silverlight 4를 개발하기 위해서는 기본적으로 Visual Studio 2010이 필요합니다. 이 이야기는 Visual Studio 2008에서는 불편하다는 이야기가 아니라 할 수 없다는 이야기 입니다. 따라서 이 강좌를 따라 해 보기 위해서는 Visual Studio 2010을 설치해 주어야 한다는 점을 강조 해 드립니다.
또 디자인 툴도 Expression Blend 4 Preview 버전을 사용하셔야 Silverlight 4 프로젝트를 사용할 수 있습니다. 이와 관련된 환경 설정은 http://www.silverlight.net/getstarted/silverlight-4-beta/ 에 가셔서 필요한 구성 요소들을 설치 할 수 있습니다.
- Visual Studio 2010 Beta 2 or Visual Web Developer Express 2010 Beta 2
- Silverlight 4 Beta Tools for Visual Studio 2010
- Microsoft Expression Blend for .NET 4 Preview
- Silverlight Toolkit (Option)
- WCF RIA Services (Option)
개발에 필요한 문서
- Online Silverlight 4 Beta Documentation
- Offline CHM help Silverlight 4 Beta Documentation file download
모든 환경을 설치하는데 다소 시간이 걸리기 때문에 마음 편히 먹고 진행하는 것이 정신 건강에 이롭습니다. 특히 Visual studio 2010의 경우는 시간이 꽤 많이 걸립니다. 이제 필요한 환경이 다 구축되었으면 Silverlight 4의 세계에 입문할 준비가 끝났습니다.
첫 번째 강좌는 RichTextArea에 관한 내용입니다. Silverlight 4에서 새롭게 추가된 RichTextArea(흔히 다른 툴이나 언어에서는 RichTextBox로 많이 부르고 있습니다.) Silverlight 4의 RichTextArea는 그 기능 만으로 보면 새로울 것 없지만 기존에 제공되지 않던 것이 이번 버전부터 제공 될 수 있게 되었다는 점에서 의미가 있습니다.
Silverlight 4 프로젝트를 생성하기 위해서 Visual Studio 2010을 실행 시키고 Silverlight Application 템플릿을 선택해서 프로젝트를 시작합니다. 프로젝트 이름은 RichText로 정했습니다.
프로젝트가 생성되고 나면 약간의 디자인 작업을 해야 합니다. Visual Studio 2010에서는 Silverlight 개발 시에 디자인 모드가 지원되지 않았지만 Visual Studio 2010 부터는 디자인 모드가 지원되기 때문에 편리하게 디자인 할 수 있습니다. 하지만 전문적인 디자인은 역시 Expression Blend를 사용해야 합니다.
화면에 나타난 폼 중에서 상단에 나타난 상하좌우 화살표를 클릭하면 Grid를 나눌 수 있는 상태가 됩니다.
Grid 분할 영역을 클릭하면 Grid 영역이 분할됩니다. 여기에 간단하게 소스 코드를 입력해서 디자인을 완성해 봅니다. RichTextArea와 버튼을 추가합니다. 각 각의 버튼은 볼드, 이텔릭, 크게, 작게 등 폰트와 관련된 속성을 변경하는 기능을 가지고 있습니다.
<UserControl x:Class="RichText.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="7*" />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Grid.Row="0"
Background="Beige">
<Button x:Name="boldButton"
Content="Bold"
FontWeight="Bold"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Margin="5"
Background="LightBlue" />
<Button x:Name="italicsButton"
Content="Italics"
FontStyle="Italic"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Margin="5"
Background="LightBlue" />
<Button x:Name="biggerButton"
Content="Bigger"
FontSize="14"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Margin="5"
Background="LightBlue" />
<Button x:Name="smallerButton"
Content="Smaller"
FontSize="10"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Margin="5"
Background="LightBlue" />
</StackPanel>
<RichTextArea x:Name="rtArea"
Grid.Row="1"
Background="Beige"
FontFamily="Georgia"
FontSize="12"
HorizontalContentAlignment="Left"
MinHeight="50"
MinWidth="50"
TextWrapping="Wrap"
VerticalContentAlignment="Top"
VerticalScrollBarVisibility="Auto" />
</Grid>
</UserControl>
이제 각 각의 버튼에 대한 C#코드를 작성해서 해당되는 기능을 완성하려고 합니다. 먼저 샘플 텍스트를 넣어줄 간단한 메소드를 추가 합니다.
private void FillText()
{
rtArea.Selection.Text = "Lrem ipsum dolor sit amet, consectetur adipiscing elit. Aenean"
+ "congue, orci ut placerat dignissim, nibh odio imperdiet diam, in porta libero lacus sit amet risus."
+ "Nullam ultrices purus nec sapien pellentesque at dignissim leo facilisis. Phasellus congue convallis metus, "
+ "eu ultrices augue malesuada sit amet. Nam varius, leo ac pretium pharetra, arcu turpis varius tellus, "
+ "vitae lacinia turpis dolor vitae mauris. Maecenas lacinia laoreet justo, eget imperdiet nulla porta eu. "
+ "Etiam nec elit vel lacus rhoncus vehicula at rutrum elit. Nunc cursus, erat vel rhoncus porta, leo ipsum venenatis "
+ " nisi, nec eleifend ligula quam non massa. Sed neque odio, euismod at egestas ac, scelerisque et nisl. Cum sociis "
+ "natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nullam ornare risus augue, nec semper "
+ "mauris. Nam feugiat suscipit arcu, sit amet mattis purus lacinia at. Sed ut purus at arcu rhoncus elementum ac at "
+ "enim. Morbi at quam ac magna rutrum gravida eu lacinia neque. Mauris purus augue, ornare sed vestibulum ac, lacinia "
+ "in sapien. Ut sit amet vehicula augue. Donec a dictum felis. In hac habitasse platea dictumst. "
+ "Pellentesque id hendrerit diam. ";
}
길어서 그렇지 그냥 문장을 계속 더해서 rtArea에 넣는 문장입니다. ^^ 그리고 각 버튼의 클릭 이벤트에 대한 이벤트 핸들러를 작성해 주어야 합니다.
boldButton.Click += new RoutedEventHandler(buttonClickHandler);
italicsButton.Click += new RoutedEventHandler(buttonClickHandler);
biggerButton.Click += new RoutedEventHandler(buttonClickHandler);
smallerButton.Click +=new RoutedEventHandler(buttonClickHandler);
네 개의 버튼 모두 buttonClickHandler라는 이벤트 핸들러를 호출하게 되어 있습니다. buttonClickHandler에서 다음과 같은 부분들을 추가 합니다.
void buttonClickHandler(object sender, RoutedEventArgs e)
{
Button b = sender as Button;
const double MaxFontSize = 36;
const double MinFontSize = 10;
const double IncrementFontSize = 2;
if (b != null)
{
switch (b.Content.ToString().ToUpper())
{
case "BOLD":
if (rtArea.FontWeight == FontWeights.Bold)
{
rtArea.FontWeight = FontWeights.Normal;
b.FontWeight = FontWeights.Bold;
}
else
{
rtArea.FontWeight = FontWeights.Bold;
b.FontWeight = FontWeights.Normal;
}
break;
case "ITALICS":
rtArea.FontStyle = rtArea.FontStyle == FontStyles.Italic ? FontStyles.Normal : FontStyles.Italic;
b.FontStyle = rtArea.FontStyle == FontStyles.Italic ? FontStyles.Normal : FontStyles.Italic;
break;
case "BIGGER":
rtArea.FontSize = rtArea.FontSize > MaxFontSize ? MaxFontSize : rtArea.FontSize + IncrementFontSize;
break;
case "SMALLER":
rtArea.FontSize = rtArea.FontSize < MinFontSize ? MaxFontSize : rtArea.FontSize - IncrementFontSize;
break;
}
}
}
어느 버튼에서 이 이벤트 핸들러를 클릭했는지 알기 위해서 sender를 버튼으로 받고 최대 글자 크기와 최소 글자 크기를 설정 하기 위해서 상수를 정의 했습니다. 그리고 증가치도 함께 설정 했습니다.
버튼이 null이 아닐 경우에 b.Content.ToString().ToUpper()를 거쳐서 버튼의 텍스트를 읽어 와서 어떤 버튼이 클릭 되어서 여기에 왔는지 구분 할 수 있게 했습니다.
BOLD의 경우 FontWeight가 Bold이면 Normal로 Normal 이면 Bold로 속성을 바꾸게 되어 있으며
ITALICS도 마찬가지로 동작을 하지만 ?를 이용한 삼항 연산자를 통해서 좀더 간결하게 표현할 수 있게 했습니다.
BIGGER와 SMALLER의 경우 폰트 크기의 최대 혹은 최소 크기가 아니면 증가값을 더하거나 뺄 수 있게 했습니다.
벌써 RichTextArea를 활용하는 샘플이 완성되었습니다. 이제 F5만 눌러 보시면 다음과 같은 결과물을 보실 수 있습니다.
주로 Silverlight와 관련된 내용들을 이야기 하고 있습니다.
")//]]>
First Look Silverlight 4 19-1 RichText.zip
댓글을 달아 주세요
좋은 강좌 감사합니다.
덕분에 많은 공부를 할 수 있었습니다.