在桌面应用程序(WPF)中使用Windows 10 API(UWP)

时间:2018-05-20 13:40:06

标签: c# wpf windows api

我已经按照这篇文章(https://blogs.windows.com/buildingapps/2017/01/25/calling-windows-10-apis-desktop-application/#PdHk3f4QeTSsSvWy.97)中的描述尝试确定Geolocator类的位置。添加引用时,它工作正常 C:\ Program Files(x86)\ Windows Kits \ 10 \ UnionMetadata \ 10.0.17134.0 \ Windows.winmd 代替 C:\ Program Files(x86)\ Windows Kits \ 10 \ UnionMetadata \ Windows.winmd 。 但是当我在下面的代码

中使用方法GetFileAsync时,我得到一个例外
    static async void LoadVoiceCommands()
    {
        try
        {
            StorageFile storageFile = await Package.Current.InstalledLocation.GetFileAsync("CustomVoiceCommandDefinitions.xml");
            await VoiceCommandDefinitionManager.InstallCommandDefinitionsFromStorageFileAsync(storageFile);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

例外情况该进程没有包标识。 (HRESULT异常:0x80073D54)

InitializeComponent

之后,我在MainWindow构造函数中调用 LoadVoiceCommands 方法

当我添加引用 C:\ Program Files(x86)\ Windows Kits \ 10 \ UnionMetadata \ Windows.winmd 而不是 C:\ Program Files(x86)\ Windows Kits \时10 \ UnionMetadata \ 10.0.17134.0 \ Windows.winmd 并使用名称空间:

using Windows.ApplicationModel; using Windows.Storage; using Windows.Devices.Geolocation;

错误 CS0731程序集“Windows”中类型的类型转发器导致循环

为行

await locator.GetGeopositionAsync();

await Package.Current.InstalledLocation.GetFileAsync("CustomVoiceCommandDefinitions.xml");

关于如何解决这个问题的任何想法? 我在谷歌找不到解决方案

1 个答案:

答案 0 :(得分:0)

某些WinRT API:s要求您的应用在应用容器的上下文中运行。

这意味着您必须转换您的应用才能使用这些。您可以使用Desktop Bridge为您的WPF桌面应用程序创建Windows应用程序包。

该软件包为您的应用程序提供了一个标识,然后使用该标识即可访问特定的WinRT API。

相关问题