为什么即使语法正确,我的 WPF window 也没有出现?

Why didn't my WPF window show up even with correct syntax?

这是代码

<Window x:Class="WpfTest.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:BobuxNotifierWpfTest"
        mc:Ignorable="d"
        Title="test app" Height="450" Width="800"
        Background="#fff0f6">
    <Grid Width="390" HorizontalAlignment="Left" Margin="10,10,0,10" Background="#ffe8f2">
        <Grid.RowDefinitions>
            <RowDefinition Height="400*"/>
            <RowDefinition Height="30*"/>
        </Grid.RowDefinitions>
        <Label FontSize="35" FontWeight="DemiBold" FontFamily="Fonts\Halyard Text Regular" Margin="10,0,10,10">
            heading
        </Label>
        <TextBlock FontSize="18" FontFamily="Fonts\Halyard Text Regular" FontWeight="DemiBold" Foreground="#633247" Margin="15,65,0,0" TextWrapping="WrapWithOverflow">
            <Label>first body line</Label>
            <Label>second body line</Label>
            <Label FontSize="12" Margin="0,20,0,0">footer</Label>
        </TextBlock>
    </Grid>
</Window>

这段代码没有给我任何错误,但是当我 运行 我得到的只是

========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

我也没有对 Main() class 或 xaml.cs 文件做任何事情

任何帮助大声笑

Application 通常是您的 WPF 项目中最重要的 类 之一,并非毫无用处。

Encapsulates a Windows Presentation Foundation application. [...]

You can implement an Application using markup, markup and code-behind, or code. If Applicationis implemented with markup, whether markup or markup and code-behind, the markup file must be configured as an Microsoft build engine (MSBuild) ApplicationDefinition item.

您必须使用 StartupUri 告诉 WPF 哪个 window 应该在启动时显示。

<Application x:Class="WpfTest.MainWindow"
             ...
             StartupUri="MainWindow.xaml">

另一种方法是添加 Startup 事件处理程序并在其中创建 window。

<Application WpfTest.MainWindow""
             ...
             Startup="OnStartup">
public partial class App : Application
{
   private void OnStartup(object sender, StartupEventArgs e)
   {
      new MainWindow().Show();
   }
}

也就是说,有可能 到 运行 没有 Application 实例的 WPF 独立应用程序。

A standalone application does not require an Application object; it is possible to implement a custom static entry point method (Main) that opens a window without creating an instance of Application.

但是,这很可能不是您想要做的,因为 the application object provides services 就像 application-wide 资源词典一样,只列出一个具有重大影响的资源词典。

Application implements the singleton pattern to provide shared access to its window, property, and resource scope services. [...]

  • Application Lifetime: Activated, Current, Deactivated, DispatcherUnhandledException, Exit, Run, SessionEnding, Shutdown, ShutdownMode, Startup.

  • Application-Scope Window, Property, and Resource Management: FindResource, GetContentStream, GetResourceStream, LoadComponent, MainWindow, Properties, Resources, StartupUri, Windows.

  • Command-Line Parameter and Exit Code Processing: Application.Startup, Application.Exit, Application.Shutdown.

  • Navigation: FragmentNavigation, LoadCompleted, Navigated, Navigating, NavigationProgress, NavigationStopped, NavigationFailed, SetCookie, GetCookie.