【发布时间】:2015-04-07 18:10:33
【问题描述】:
我正在编写我的第一个 Windows 应用商店应用程序(Windows 8.1),我注意到当我在调试模式下运行它时,我关闭了应用程序(通过单击右上角的 x 或从顶部拖动屏幕到底部),它仍在 Visual Studio 中运行。我的第一个问题是,这是一个问题吗?好像有问题。
我从一个模板开始,我没有对线程做任何事情,目前只有一个页面 (MainPage.xaml)。我看过看起来相似的问题,特别是这个: WPF App Doesn't Shut Down When Closing Main Window 但我无法让他们的建议发挥作用。
当我将 ShutdownMode="OnExplicitShutdown" 添加到我的 app.xaml 时,我的错误列表中出现了这些错误:
- 成员“ShutdownMode”无法识别或无法访问。
- 在“应用程序”类型中找不到属性“ShutdownMode”。
我还注意到没有指定 StartupUri,我也不能添加一个(与上面相同的错误。)
另一个建议是覆盖 MainWindow.xaml.cs 中的 OnClosed 并在那里关闭应用程序。我没有 MainWindow.xaml.cs;我有 MainPage.xaml.cs,但它没有 OnClosed。
Application 类的类型为Windows.UI.Xaml.Application。
如果我在关闭应用程序后暂停 VS,它会将我带到这个(生成的)代码:
#if !DISABLE_XAML_GENERATED_MAIN
public static class Program
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Windows.UI.Xaml.Build.Tasks"," 4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
static void Main(string[] args)
{
global::Windows.UI.Xaml.Application.Start((p) => new App()); //<==here
}
}
#endif
谁能告诉我这是怎么回事?
【问题讨论】: