2012-01-12 77 views
0

我写了最简单的WPF Prism应用程序。它不关机。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> 

为什么会是这种情况?

+0

只需从App.xaml中删除StartupUri =“Shell.xaml”,看看发生了什么?你仍然不允许引导程序加载你的Shell并且让StartupUri结束。 – 2012-01-12 05:36:03

+0

初创Uri是你的问题。 Theck出这个[交] [1] [1]:http://stackoverflow.com/questions/4114956/prism-app-does-not-exit-when-closed/11987246 #11987246 – Adys 2012-08-16 13:06:20

回答

0

我刚看过我的棱镜项目,设置稍有不同。也许这将有助于

在App.xaml中,我做

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

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

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

,并在我的引导程序。 cs

Shell _shell; 

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

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

其中shell是我的WPF窗口

+1

你意识到你不必定义自己的'Shell'字段,因为'Bootstrapper'已经提供了一个Shell属性。此外,而不是ShowDefaultView,你应该重写'InitializeShell'。 – 2012-01-12 05:44:16

相关问题