feat: WPF路由事件-4-生命周期

This commit is contained in:
Bunny 2025-01-01 21:56:07 +08:00
parent ec184c6e5f
commit 7368afd24c
7 changed files with 132 additions and 0 deletions

View File

@ -58,6 +58,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF路由事件-2-事件路
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF路由事件-3-冒泡路由事件", "WPF路由事件-3-冒泡路由事件\WPF路由事件-3-冒泡路由事件.csproj", "{9300CA90-12F2-418C-BA84-4A774716977C}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF路由事件-3-冒泡路由事件", "WPF路由事件-3-冒泡路由事件\WPF路由事件-3-冒泡路由事件.csproj", "{9300CA90-12F2-418C-BA84-4A774716977C}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF路由事件-4-生命周期", "WPF路由事件-4-生命周期\WPF路由事件-4-生命周期.csproj", "{B5A965AA-9C4C-4EB3-8515-DF03F948EC14}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -180,5 +182,9 @@ Global
{9300CA90-12F2-418C-BA84-4A774716977C}.Debug|Any CPU.Build.0 = 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.ActiveCfg = Release|Any CPU
{9300CA90-12F2-418C-BA84-4A774716977C}.Release|Any CPU.Build.0 = Release|Any CPU {9300CA90-12F2-418C-BA84-4A774716977C}.Release|Any CPU.Build.0 = Release|Any CPU
{B5A965AA-9C4C-4EB3-8515-DF03F948EC14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B5A965AA-9C4C-4EB3-8515-DF03F948EC14}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B5A965AA-9C4C-4EB3-8515-DF03F948EC14}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B5A965AA-9C4C-4EB3-8515-DF03F948EC14}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

View File

@ -0,0 +1,9 @@
<Application x:Class="WPF路由事件_4_生命周期.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPF路由事件_4_生命周期"
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路由事件_4_生命周期;
/// <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,14 @@
<Window x:Class="WPF路由事件_4_生命周期.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"
Title="MainWindow" Height="450" Width="800" SourceInitialized="MainWindow_OnSourceInitialized"
ContentRendered="MainWindow_OnContentRendered" Activated="MainWindow_OnActivated"
Deactivated="MainWindow_OnDeactivated" Closing="MainWindow_OnClosing" Closed="MainWindow_OnClosed">
<Grid Initialized="FrameworkElement_OnInitialized" Loaded="FrameworkElement_OnLoaded"
Unloaded="FrameworkElement_OnUnloaded">
<ListBox Name="ListBox" />
</Grid>
</Window>

View File

@ -0,0 +1,69 @@
using System.ComponentModel;
using System.Windows;
namespace WPF路由事件_4_生命周期;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void FrameworkElement_OnInitialized(object? sender, EventArgs e)
{
Console.WriteLine("初始化。。。");
ListBox.Items.Add("初始化。。。");
}
private void MainWindow_OnSourceInitialized(object? sender, EventArgs e)
{
Console.WriteLine("主窗口开始初始化。。。");
ListBox.Items.Add("主窗口开始初始化。。。");
}
private void MainWindow_OnActivated(object? sender, EventArgs e)
{
Console.WriteLine("Activated...");
ListBox.Items.Add("Activated...");
}
private void FrameworkElement_OnUnloaded(object sender, RoutedEventArgs e)
{
Console.WriteLine("加载完成。。。");
ListBox.Items.Add("加载完成。。。");
}
private void FrameworkElement_OnLoaded(object sender, RoutedEventArgs e)
{
Console.WriteLine("开始加载。。。");
ListBox.Items.Add("开始加载。。。");
}
private void MainWindow_OnContentRendered(object? sender, EventArgs e)
{
Console.WriteLine("主窗口---MainWindow_OnContentRendered");
ListBox.Items.Add("主窗口---MainWindow_OnContentRendered");
}
private void MainWindow_OnClosing(object? sender, CancelEventArgs e)
{
Console.WriteLine("Closing...");
ListBox.Items.Add("Closing...");
}
private void MainWindow_OnDeactivated(object? sender, EventArgs e)
{
Console.WriteLine("Deactivated...");
ListBox.Items.Add("Deactivated...");
}
private void MainWindow_OnClosed(object? sender, EventArgs e)
{
Console.WriteLine("Closed...");
ListBox.Items.Add("Closed...");
}
}

View File

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<RootNamespace>WPF路由事件_4_生命周期</RootNamespace>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>