【问题标题】:How to Interop with Windows Runtime in .NET 4.5如何在 .NET 4.5 中与 Windows 运行时互操作
【发布时间】:2012-04-25 07:10:13
【问题描述】:

我看到了这个命名空间:

System.Runtime.InteropServices.WindowsRuntime

提供 .NET 和 WindowsRuntime 之间的互操作。

例如,您可以在创建 Metro 应用程序时调用 WindowsRuntime 中的方法,因为 Metro 使用 WindowsRuntime,就像

Windows.System.UserProfile.UserInformation

但是当你创建一个普通的 .NET 控制台应用程序或 WPF 应用程序时,你无法再直接访问 Windows.System 等 WindowsRuntime 命名空间

我想知道是否可以通过在上述命名空间中使用互操作来调用 WindowsRuntime 方法。

提前非常感谢!

【问题讨论】:

    标签: c# .net microsoft-metro windows-runtime .net-4.5


    【解决方案1】:

    .NET 控制台模式应用程序或 WPF 应用程序不是 Metro 应用程序。它们只能在“常规”版本的 Windows 上运行。 Windows 8 中的传统桌面。因此不能与 WinRT 互操作,它不会在进程中加载​​。以 WinRT 为目标需要在您启动项目时选择特定的 Metro 项目模板。

    【讨论】:

      【解决方案2】:

      您需要将此添加到项目文件中:

      <PropertyGroup>
        <TargetPlatformVersion>8.1</TargetPlatformVersion>
      </PropertyGroup>
      

      更多详情请见How to use specific WinRT API from Desktop apps

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-12-27
        • 2018-11-29
        • 1970-01-01
        • 2018-05-27
        • 2013-10-06
        • 2012-08-17
        • 2015-09-02
        • 1970-01-01
        相关资源
        最近更新 更多