feat: WPF路由事件-2-事件路由

This commit is contained in:
Bunny 2025-01-01 20:57:53 +08:00
parent cc2ba06ebe
commit 29f9db5920
10 changed files with 106 additions and 0 deletions

View File

@ -54,6 +54,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF基础-11-动态布局",
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF路由事件-1-引发路由事件", "WPF路由事件-1-引发路由事件\WPF路由事件-1-引发路由事件.csproj", "{1B8F7458-502C-45A7-9C47-1EF772DD7E19}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF路由事件-1-引发路由事件", "WPF路由事件-1-引发路由事件\WPF路由事件-1-引发路由事件.csproj", "{1B8F7458-502C-45A7-9C47-1EF772DD7E19}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF路由事件-2-事件路由", "WPF路由事件-2-事件路由\WPF路由事件-2-事件路由.csproj", "{AB34E12C-1E74-45AA-9085-6CAA81361E90}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -168,5 +170,9 @@ Global
{1B8F7458-502C-45A7-9C47-1EF772DD7E19}.Debug|Any CPU.Build.0 = Debug|Any CPU {1B8F7458-502C-45A7-9C47-1EF772DD7E19}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1B8F7458-502C-45A7-9C47-1EF772DD7E19}.Release|Any CPU.ActiveCfg = Release|Any CPU {1B8F7458-502C-45A7-9C47-1EF772DD7E19}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1B8F7458-502C-45A7-9C47-1EF772DD7E19}.Release|Any CPU.Build.0 = Release|Any CPU {1B8F7458-502C-45A7-9C47-1EF772DD7E19}.Release|Any CPU.Build.0 = Release|Any CPU
{AB34E12C-1E74-45AA-9085-6CAA81361E90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

View File

@ -0,0 +1,9 @@
<Application x:Class="WPF路由事件_2_事件路由.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPF路由事件_2_事件路由"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

View File

@ -0,0 +1,12 @@
using System.Configuration;
using System.Data;
using System.Windows;
namespace WPF路由事件_2_事件路由;
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}

View File

@ -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)
)]

View File

@ -0,0 +1,16 @@
<Window x:Class="WPF路由事件_2_事件路由.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"
mc:Ignorable="d"
Icon="public/logo/1.ico"
Title="WPF路由事件_2_事件路由" Height="450" Width="800">
<Label BorderBrush="Black" BorderThickness="10">
<StackPanel>
<TextBlock Margin="3">图片和文本的内容</TextBlock>
<Image Source="public/images/003540AH4M72.jpg" Width="322" MouseUp="UIElement_OnMouseUp" />
<TextBlock Margin="3">内容信息</TextBlock>
</StackPanel>
</Label>
</Window>

View File

@ -0,0 +1,29 @@
using System.Windows;
namespace WPF路由事件_2_事件路由;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void UIElement_OnMouseUp(object sender, RoutedEventArgs routedEventArgs)
{
var source = routedEventArgs.Source;
Console.WriteLine($"source:{source}");
var routedEventName = routedEventArgs.RoutedEvent.Name;
Console.WriteLine($"RoutedEvent.Name:{routedEventName}");
var originalSource = routedEventArgs.OriginalSource;
Console.WriteLine($"OriginalSource:{originalSource}");
var handled = routedEventArgs.Handled;
Console.WriteLine($"Handled:{handled}");
}
}

View File

@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<RootNamespace>WPF路由事件_2_事件路由</RootNamespace>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<Resource Include="public\images\003540AH4M72.jpg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="public\logo\1.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="public\logo\1.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
</ItemGroup>
</Project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB