Blog Content

    티스토리 뷰

    51.SilverLight3 - RoutedEventArgs

    반응형
    Event Routing
    - RoutedEventArgs 클래스 : 이벤트 발생을 수신기에서 처리기를 호출 할 수 있는 이벤트 형식

    MainPage.xaml

    [그림 51-1]


    <Grid x:Name="LayoutRoot" Background="White">

            <Rectangle x:Name="rect" Fill="Red" Margin="20"></Rectangle>

            <TextBlock x:Name="lbl" Text="" FontSize="30" Foreground="Yellow"

                       Width="100" Height="50"/>

    </Grid>


    MainPage.xaml.cs

    public partial class MainPage : UserControl

    {

        public MainPage()

        {

            InitializeComponent();

     

            //

            this.LayoutRoot.MouseLeftButtonUp += new

                            MouseButtonEventHandler(LayoutRoot_MouseLeftButtonUp);

            //

            this.rect.MouseLeftButtonUp += new

                      MouseButtonEventHandler(rect_MouseLeftButtonUp);

            //

            this.lbl.MouseLeftButtonUp += new

                     MouseButtonEventHandler(lbl_MouseLeftButtonUp);

        }

     

        void lbl_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)

        {

            MessageBox.Show(" : ");

            // ( ) :

            e.Handled = true;

        }

     

        void rect_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)

        {

            MessageBox.Show(" : ");

        }

     

        void LayoutRoot_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)

        {

            MessageBox.Show(" : ");

            //[!]

            if (e.OriginalSource is Rectangle)

            {

                //

                Rectangle r = e.OriginalSource as Rectangle;

                r.Fill = new SolidColorBrush(Colors.Blue);

            }

        }

    }


    결과화면

    [그림 51-2]



    반응형

    'Silverlight' 카테고리의 다른 글

    53.SilverLight3 - HyperlinkButton  (0) 2009.12.02
    52.SilverLight3 - AttachedProperty  (0) 2009.12.02
    50.SilverLight3 - InkPresenter  (0) 2009.12.01
    49.SilverLight3 - DragAndDrop  (0) 2009.12.01
    48.SilverLight3 - TextBlock  (0) 2009.12.01

    Comments