Search code examples
wpfxamldebuggingstartupvisual-studio-2022

How do I start debugging a new app in visual studio 2022?


I created a new WPF app in Visual Studio 2022 targeting .Net 6.0. It will not start when I hit F5 or click on the green Start icon. It is set to Debug mode, Any CPU. The properties has only one project a startup and that is the project I am trying to start. It is running (because the red stop icon is active and the green start icon is not). But my main view is not visible anywhere on the computer. A break point in the App.xaml.cs in Application_Startup is not being hit at all.

public partial class App : Application
{
    private MainWindowView? main;
    private void Application_Startup(object sender, StartupEventArgs e)
    {
        main = new MainWindowView
        {
            DataContext = new MainWindowViewModel()
        };
        main.Show();
    }

    public static event EventHandler? OnEndApplication;

    /// <summary>
    /// Program exit logic
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void ExitEventHandler(object sender, ExitEventArgs e)
    {
        OnEndApplication?.Invoke(this, EventArgs.Empty);
    }
}

The MainWindowView xaml is this

<Window x:Class="Prep.Views.MainWindowView"
    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="Prep" Height="450" Width="800">

<Window.Resources>
    <ResourceDictionary Source="./ViewResources.xaml" />
</Window.Resources>

<Grid>
</Grid>

I don't know where else to look.

Thank you.


Solution

  • Maybe you can check the App.xaml. Here is a example about Application.Startup Event:

    <Application
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      x:Class="SDKSample.App"
      Startup="App_Startup" />
    

    You can delete StartUpUri and use Startup="Application_Startup" in App.xaml. Hope it can help you.