debugging 如何在visual studio 2022中开始调试新的应用程序?

pxq42qpu  于 2022-11-14  发布在  其他
关注(0)|答案(1)|浏览(211)

我在VisualStudio 2022中创建了一个面向.Net6.0的新WPF应用程序。当我按F5键或单击绿色“启动”图标时,它不会启动。它被设置为调试模式,任何CPU。该属性只有一个项目启动,这是我试图启动的项目。它正在运行(因为红色的停止图标是活动的,而绿色的开始图标不是)。但是我的主视图在计算机上的任何地方都是不可见的。Application_Startup中的App.xaml.cs中的断点根本没有被命中。

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);
    }
}

主窗口视图xaml是这样的

<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>

我不知道还能去哪儿找。

  • 谢谢-谢谢
9rbhqvlz

9rbhqvlz1#

也许你可以检查App.xaml。下面是一个关于Application.Startup事件的例子:

<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" />

您可以删除StartUpUri并使用App.xaml中的Startup=“Application_Startup”。希望它能对您有所帮助。

相关问题