我在面向 .Net 6.0 的 Visual Studio 2022 中創建了一個新的 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);
}
}
MainWindowView 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>
我不知道還能去哪里看。
謝謝你。
uj5u.com熱心網友回復:
也許您可以檢查 App.xaml。這是一個關于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" />
您可以洗掉 StartUpUri 并在 App.xaml 中使用 Startup="Application_Startup"。希望它可以幫助你。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/526010.html
