36 lines
993 B
C#
36 lines
993 B
C#
|
using System.Windows;
|
|||
|
using System.Windows.Input;
|
|||
|
|
|||
|
namespace WPF路由事件_3_冒泡路由事件;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Interaction logic for MainWindow.xaml
|
|||
|
/// </summary>
|
|||
|
public partial class MainWindow
|
|||
|
{
|
|||
|
private int _eventCount;
|
|||
|
|
|||
|
public MainWindow()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
|
|||
|
// 如果最后一个参数设置为 true即使让 e.Handled 为true也还是会接受到
|
|||
|
CmdClear.AddHandler(MouseUpEvent, new MouseButtonEventHandler(CmdClear_OnClick), true);
|
|||
|
}
|
|||
|
|
|||
|
private void MainWindow_OnMouseUp(object sender, MouseButtonEventArgs e)
|
|||
|
{
|
|||
|
_eventCount++;
|
|||
|
|
|||
|
var message = $"#{_eventCount}:\r\nSender:{sender}\r\nSource:{e.Source}\r\nOriginal Source:{e.OriginalSource}";
|
|||
|
ListBoxMessage.Items.Add(message);
|
|||
|
|
|||
|
// 阻止事件冒泡
|
|||
|
e.Handled = (bool)CheckBoxHandle.IsChecked!;
|
|||
|
}
|
|||
|
|
|||
|
private void CmdClear_OnClick(object sender, RoutedEventArgs e)
|
|||
|
{
|
|||
|
ListBoxMessage.Items.Clear();
|
|||
|
}
|
|||
|
}
|