diff --git a/WPF基础.sln b/WPF基础.sln index b7124f5..4b4e801 100644 --- a/WPF基础.sln +++ b/WPF基础.sln @@ -56,6 +56,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF路由事件-1-引发路 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF路由事件-2-事件路由", "WPF路由事件-2-事件路由\WPF路由事件-2-事件路由.csproj", "{AB34E12C-1E74-45AA-9085-6CAA81361E90}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF路由事件-3-冒泡路由事件", "WPF路由事件-3-冒泡路由事件\WPF路由事件-3-冒泡路由事件.csproj", "{9300CA90-12F2-418C-BA84-4A774716977C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -174,5 +176,9 @@ Global {AB34E12C-1E74-45AA-9085-6CAA81361E90}.Debug|Any CPU.Build.0 = Debug|Any CPU {AB34E12C-1E74-45AA-9085-6CAA81361E90}.Release|Any CPU.ActiveCfg = Release|Any CPU {AB34E12C-1E74-45AA-9085-6CAA81361E90}.Release|Any CPU.Build.0 = Release|Any CPU + {9300CA90-12F2-418C-BA84-4A774716977C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9300CA90-12F2-418C-BA84-4A774716977C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9300CA90-12F2-418C-BA84-4A774716977C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9300CA90-12F2-418C-BA84-4A774716977C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/WPF路由事件-3-冒泡路由事件/App.xaml b/WPF路由事件-3-冒泡路由事件/App.xaml new file mode 100644 index 0000000..8fc8906 --- /dev/null +++ b/WPF路由事件-3-冒泡路由事件/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/WPF路由事件-3-冒泡路由事件/App.xaml.cs b/WPF路由事件-3-冒泡路由事件/App.xaml.cs new file mode 100644 index 0000000..5d9471d --- /dev/null +++ b/WPF路由事件-3-冒泡路由事件/App.xaml.cs @@ -0,0 +1,12 @@ +using System.Configuration; +using System.Data; +using System.Windows; + +namespace WPF路由事件_3_冒泡路由事件; + +/// +/// Interaction logic for App.xaml +/// +public partial class App : Application +{ +} \ No newline at end of file diff --git a/WPF路由事件-3-冒泡路由事件/AssemblyInfo.cs b/WPF路由事件-3-冒泡路由事件/AssemblyInfo.cs new file mode 100644 index 0000000..4a05c7d --- /dev/null +++ b/WPF路由事件-3-冒泡路由事件/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] \ No newline at end of file diff --git a/WPF路由事件-3-冒泡路由事件/MainWindow.xaml b/WPF路由事件-3-冒泡路由事件/MainWindow.xaml new file mode 100644 index 0000000..b93aab8 --- /dev/null +++ b/WPF路由事件-3-冒泡路由事件/MainWindow.xaml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + Handle first event + + + \ No newline at end of file diff --git a/WPF路由事件-3-冒泡路由事件/MainWindow.xaml.cs b/WPF路由事件-3-冒泡路由事件/MainWindow.xaml.cs new file mode 100644 index 0000000..60a49ad --- /dev/null +++ b/WPF路由事件-3-冒泡路由事件/MainWindow.xaml.cs @@ -0,0 +1,36 @@ +using System.Windows; +using System.Windows.Input; + +namespace WPF路由事件_3_冒泡路由事件; + +/// +/// Interaction logic for MainWindow.xaml +/// +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(); + } +} \ No newline at end of file diff --git a/WPF路由事件-3-冒泡路由事件/WPF路由事件-3-冒泡路由事件.csproj b/WPF路由事件-3-冒泡路由事件/WPF路由事件-3-冒泡路由事件.csproj new file mode 100644 index 0000000..7a2d420 --- /dev/null +++ b/WPF路由事件-3-冒泡路由事件/WPF路由事件-3-冒泡路由事件.csproj @@ -0,0 +1,21 @@ + + + + WinExe + net8.0-windows + WPF路由事件_3_冒泡路由事件 + enable + enable + true + + + + + Always + + + Always + + + + diff --git a/WPF路由事件-3-冒泡路由事件/public/logo.ico b/WPF路由事件-3-冒泡路由事件/public/logo.ico new file mode 100644 index 0000000..d7bff7f Binary files /dev/null and b/WPF路由事件-3-冒泡路由事件/public/logo.ico differ diff --git a/WPF路由事件-3-冒泡路由事件/public/test-image.jpg b/WPF路由事件-3-冒泡路由事件/public/test-image.jpg new file mode 100644 index 0000000..4aa96ac Binary files /dev/null and b/WPF路由事件-3-冒泡路由事件/public/test-image.jpg differ