2/05/2010

Sliverlight 3 시작하기 + Tutorial 1: Silverlight User Interface Controls

참고자료 링크 클릭

Sliverlight 3 개발을 시작하려면?
  • vs 2008 설치
  • vs 2008 SP1 설치 download
  • blend 3 sketchflow [이건 설치를 해야하나 말아야하나. 일단 보류!]
  • silverlight tools for vs2008 SP1 설치 download
  • Deep Zoom Composer 설치 download
  • .NET RIA Services [이것도 좀 알아보자. 보류!]
http://silverlight.net/getstarted/ 에서 설치를 마치고
http://silverlight.net/learn/tutorials/controls-cs/ 에서 튜토리얼을 보자!

Tutorial 1: Silverlight User Interface Controls


어려운 내용이 없으니 간단히 소스코드만...
Hello 버튼은 아무것도 아니고 Rush CheckBox는 체크되면 대문자로 Un체크되면 소문자로 바뀐다.
Add Another 버튼을 누르면 새로운 버튼이 동적으로 생겨나는 예제이다.
처음으로 실버라이트를 접하기에 안성맞춤인 예제!

MainPage.xaml 파일

    
        
        
        
    


MainPage.xaml.cs 파일
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace EasyGrid
{
    public partial class MainPage : UserControl
    {
        private double newButtonPosition = 100.0;

        public MainPage()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            Another.Click += new RoutedEventHandler(Another_Click);
            rushOrder.Checked += new RoutedEventHandler(rushOrder_Changed);
            rushOrder.Unchecked += new RoutedEventHandler(rushOrder_Changed);
        }

        void rushOrder_Changed(object sender, RoutedEventArgs e)
        {
            if (rushOrder.IsChecked == true)
            {
                rushOrder.Content = rushOrder.Content.ToString().ToUpper();
            }
            else
            {
                rushOrder.Content = rushOrder.Content.ToString().ToLower();
            }
        }

        void Another_Click(object sender, RoutedEventArgs e)
        {
            Button b = new Button();
            b.Content = "I Live";
            b.SetValue(Canvas.LeftProperty, 10.0);
            b.SetValue(Canvas.TopProperty, this.newButtonPosition);
            this.newButtonPosition += 30.0;
            b.Width = 100;
            b.Height = 20;
            b.Click += new RoutedEventHandler(new_button_click);
            myCanvas.Children.Add(b);
        }

        void new_button_click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;
            btn.Content = "Don't do that!";
            btn.IsEnabled = false;
        }

        private void Canvas_Loaded(object sender, RoutedEventArgs e)
        {
            myButton.Content = "Please Click Me";
        }
    }
}

참고자료:
silverlight start: http://silverlight.net/getstarted/
tutorial 1: http://silverlight.net/learn/tutorials/controls-cs/

댓글 없음:

댓글 쓰기