본문 바로가기

Programing (프로그래밍)/WPF & C# (C Sharp)

WPF & C# - 이벤트 라우팅 버블링/터널링/직접전달 테스트 ( Bubbling / Tunneling / direct / e.Handled = true )

728x90
반응형


 WPF & C# - 이벤트 라우팅 버블링/터널링/직접전달 테스트 ( Bubbling / Tunneling / direct / e.Handled = true )



WpfApp11.zip





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



728x90
반응형