0

我编写了最简单的 WPF Prism 应用程序。它不会关闭。

应用程序.xaml

<Application x:Class="PrismApp.Desktop.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="Shell.xaml"
             ShutdownMode="OnMainWindowClose">
    <Application.Resources>

    </Application.Resources>
</Application>

应用程序.xaml.cs

namespace PrismApp.Desktop
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            Bootstrapper bootstrapper = new Bootstrapper();
            bootstrapper.Run();
        }
    }
}

引导程序.cs

namespace PrismApp.Desktop
{
    class Bootstrapper : UnityBootstrapper
    {
        protected override System.Windows.DependencyObject CreateShell()
        {
            var shell = new Shell();
            return shell;
        }

        protected override void ConfigureModuleCatalog()
        {
            base.ConfigureModuleCatalog();
        }
    }
}

壳牌.xaml

<Window x:Class="PrismApp.Desktop.Shell"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Shell" Height="350" Width="525">
    <Grid>

    </Grid>
</Window>

为什么会这样?

4

1 回答 1

0

我刚刚浏览了我的 prism 项目,设置略有不同。也许会有所帮助

在 app.xaml中,我没有

StartupUri="Shell.xaml"
ShutdownMode="OnMainWindowClose"

然后在 app.xaml.cs 我有以下

private void StartupContainer()
{
   Bootstrapper bootstrapper = new Bootstrapper();
   bootstrapper.Run();
   bootstrapper.ShowDefaultView();
}

在我的 bootstrapper.cs

Shell _shell;

protected override DependencyObject CreateShell()
{
    _shell = Container.Resolve<Shell>();
    return _shell;
}

public void ShowDefaultView()
{
    _shell.Show();
}

Shell 是我的 WPF 窗口

于 2012-01-12T05:38:33.227 回答