我如何使用Windows.UI命名空间从常规(无店铺)的Win32 .NET应用程序?如何使用、应用程序、常规、店铺

2023-09-02 10:49:48 作者:迷人的风景

这个问题基本上是与Possible使用敬酒通知从一个普通的.NET应用程序?

我如何使用Windows.UI命名空间从常规(无店铺)的Win32 .NET应用程序(控制台,的WinForms,WPF)?

How can I use the Windows.UI namespace from a regular (Non-Store) Win32 .NET application (Console, WinForms, WPF)?

推荐答案

某些WinRT的类可以从桌面应用程序,包括Windows.UI命名空间的一部分使用。敬酒通知API是一个这样的例子 - 它们可以同时用于Windows应用商店的应用程序和桌面应用程序。在API参考部分,每一类网页显示,如果API适用于Windows应用商店的应用程序或桌面应用程序(的例如,对于敬酒)。有使用Toast通知的API从桌面应用提供一个样本MSDN上。

Certain WinRT classes can be used from desktop apps, including portions of the Windows.UI namespace. The toast notification APIs are one such example - they can be used by both Windows Store apps and desktop apps. In the API reference section, each class page shows if the API applies to Windows Store apps or desktop apps (example for toast). There is a sample of using the toast notification APIs from a desktop app provided on MSDN.

MSDN包含一个full在WinRT的类可用于台式机的列表应用。

编辑:

添加一个引用到的WinRT API的能力是默认关闭在C#桌面应用程序。该项目需要专门针对Windows 8的平台。要添加引用的WinRT的API(该Windows.winmd组装),以下内容添加到您的项目文件:

The ability to add a reference to the WinRT APIs is off by default in C# desktop apps. The project needs to specifically target the Windows 8 platform. To add a reference to WinRT APIs (the Windows.winmd assembly), add the following to your project file:

<PropertyGroup>
    <TargetPlatformVersion>8.0</TargetPlatformVersion>
</PropertyGroup>

补充说,该项目建成后,一个Windows选项卡将出现在引用管理器对话框,您可以添加Windows组件。欲了解更多信息,请参阅核心小组在此 MSDN文章。