728x90
반응형
WPF & C# - 이벤트 라우팅 버블링/터널링/직접전달 테스트 ( Bubbling / Tunneling / direct / e.Handled = true ) |
MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <Window x:Class="WpfApp11.MainWindow" 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" xmlns:local="clr-namespace:WpfApp11" mc:Ignorable="d" Title="MainWindow" Height="400" Width="445.994" Background="#FFFFFBD6" MouseDown="Window_MouseDown"> <Grid> <Button HorizontalAlignment="Left" Height="300" Margin="10,10,0,0" VerticalAlignment="Top" Width="300" PreviewMouseDown="Button_PreviewMouseDown"> <Grid Height="250" Width="250" MouseDown="Grid_MouseDown"> <Ellipse x:Name="Ellipse1" Fill="Yellow" Height="100" Width="100" MouseDown="Ellipse1_MouseDown" Margin="10,75,140,75"></Ellipse> <Ellipse x:Name="Ellipse2" Fill="Red" Height="100" Width="100" MouseDown="Ellipse2_MouseDown" Margin="140,75,10,75"/> </Grid> </Button> <Label x:Name="lbl" Content="Label" HorizontalAlignment="Left" Margin="315,10,-22,0" VerticalAlignment="Top" Height="300" Width="99" MouseDown="lbl_MouseDown" Background="#FFFFC9C9"/> </Grid> </Window> | cs |
MainWindow.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | private void Ellipse2_MouseDown(object sender, MouseButtonEventArgs e) { lbl.Content += "Ellipse2" + "\n"; e.Handled = true; } private void Ellipse1_MouseDown(object sender, MouseButtonEventArgs e) { lbl.Content += "Ellipse1" + "\n"; e.Handled = false; } private void Rectangle_MouseDown(object sender, MouseButtonEventArgs e) { lbl.Content += "Rectangle" + "\n"; e.Handled = false; } private void Grid_MouseDown(object sender, MouseButtonEventArgs e) { lbl.Content += "Grid" + "\n"; e.Handled = false; } private void lbl_MouseDown(object sender, MouseButtonEventArgs e) { lbl.Content = ""; } private void Window_MouseDown(object sender, MouseButtonEventArgs e) { lbl.Content += "Window" + "\n"; } private void Button_PreviewMouseDown(object sender, MouseButtonEventArgs e) { lbl.Content += "Button" + "\n"; e.Handled = false; } | cs |
e.Handled = true; // 버블링 종료
e.Handled = false; // 버블링 허락
버블링과 터널링
참고할만한 곳
http://cafe.naver.com/kusdoblee/173
https://docs.microsoft.com/ko-kr/dotnet/framework/wpf/advanced/input-overview
https://docs.microsoft.com/ko-kr/dotnet/framework/wpf/advanced/routed-events-overview
728x90
반응형
'Programing (프로그래밍) > WPF & C# (C Sharp)' 카테고리의 다른 글
WPF & C# - Listbox, List<string> ( 리스트박스 / 추가 / 제거 / binding / 바인딩) (0) | 2018.05.25 |
---|---|
WPF & C# - List<string> 동적 배열 ( 리스트 / array / dictionary ) (0) | 2018.05.24 |
WPF & C# - 색상변환 / 브러쉬, 컬러 ( Brush <-> Color / SolidColorBrush / 색상 형변환) (0) | 2018.05.24 |
[자작] WPF & C# - TouchTotalCount ( 터치 수 확인 프로그램 ) (0) | 2018.05.23 |
WPF & C# - Color Name Table (컬러 / RGB / 색상) (0) | 2018.05.23 |
WPF & C# 컨트롤 접두사 명명 규칙 (0) | 2018.05.22 |
WPF & C# - Environment 정보 값 읽어오기 ( 각종 폴더 및 OS 정보 / SpecialFolder / 스폐셜폴더 ) (0) | 2018.05.11 |
WPF & C# - 중복실행 방지 ( WPF용 / Mutex 활용 ) (0) | 2018.05.10 |