- 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