【发布时间】:2012-01-12 00:43:10
【问题描述】:
我编写了最简单的 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>
为什么会这样?
【问题讨论】:
-
只需从 App.xaml 中删除 StartupUri="Shell.xaml" 看看发生了什么?您仍然不允许引导程序加载您的 Shell,并且 StartupUri 已被接管。
-
启动 Uri 是你的问题。查看此 [post][1] [1]:stackoverflow.com/questions/4114956/…