WPF Prism应用程序不关机

时间:2012-01-12 00:43:11

标签: wpf prism-4

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

的App.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>

App.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();
        }
    }
}

Bootstrapper.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();
        }
    }
}

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

为什么会出现这种情况?

1 个答案:

答案 0 :(得分:0)

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

在app.xaml中,我 NOT

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