When a simple WPF program starts, the loaded method does not trigger, and the window displays a prompt indicating no response, followed by a crash

Sarzn 1 Reputation point
2023-10-16T07:54:16.87+00:00
<Window x:Class="WpfApplication1.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:WpfApplication1"
        mc:Ignorable="d"
        Loaded="Window_Loaded"
        Unloaded="Window_Unloaded"
        Activated="Window_Activated"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        
    </Grid>
</Window>



namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Console.WriteLine("create");
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Console.WriteLine("loaded");
        }

        private void Window_Unloaded(object sender, RoutedEventArgs e)
        {
            Console.WriteLine("unloaded");
        }

        private void Window_Activated(object sender, EventArgs e)
        {
            Console.WriteLine("Activated");
        }
    }
}
Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,195 questions
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,710 questions
{count} votes