2012-01-12 59 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

相關問題