如何在 WPF 应用程序中使用 SystemMediaTransportControls? [英] How to use SystemMediaTransportControls in WPF Application?

查看:74
本文介绍了如何在 WPF 应用程序中使用 SystemMediaTransportControls?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 WPF 中创建 SystemMediaTransportControls 对象?

Is there any way to create an SystemMediaTransportControls-object in WPF?

我关注了这个 从我的 WPF 应用程序访问 Windows 10 API 的指南.我可以调用该类,但无法创建对象.在 UWP 应用程序中,您可以像这样创建它:

I followed this guide to access the Windows 10 APIs from my WPF-Application. I can call the class but I can't create an object. In a UWP-App you create it like this:

SystemMediaTransportControls smtp = SystemMediaTransportControls.GetForCurrentView();

但是通过在 WPF 中调用这个方法,我在这一行得到了一个 "Invalid window handle" 异常.

But by calling this method in WPF, I'm getting an "Invalid window handle" exception at this line.

public partial class MainWindow : Window
{
    SystemMediaTransportControls smtp;

    public MainWindow()
    {
        InitializeComponent();
        //SMTP Einrichten
        smtp = SystemMediaTransportControls.GetForCurrentView();
    }

[...]
}

显然,GetForCurrentView() 在 WPF 中不起作用,但该用什么代替?

Apparently, GetForCurrentView() is not working in WPF but what to use instead?

推荐答案

SystemMediaTransportControls 在桌面应用程序中不受支持.它只能在 UWP 应用中使用.

SystemMediaTransportControls isn't supported in desktop apps. It can only be used in UWP apps.

参见 可从经典桌面应用程序调用的 UWP API,其中说:

如果未列出 DualApiPartition 属性

在这种情况下,API不允许从经典桌面应用程序调用.Windows.UI.Xaml.Controls.Button 就是一个例子.

In this case, the API is not allowed to be called from a classic desktop app. Windows.UI.Xaml.Controls.Button is an example.

SystemMediaTransportControls 没有 DualApiPartition 属性.

SystemMediaTransportControls does not have the DualApiPartition attribute.

我如何知道哪些 API 可用?您链接的指南部分引用了UWP API 可用于打包的桌面应用程序(桌面桥),并且这也没有将 SystemMediatTransportControls 列为可用.

The How do I know which APIs are available? section of guide you linked references the list of UWP APIs available to a packaged desktop app (Desktop Bridge) , and this also does not list SystemMediatTransportControls as available.

这篇关于如何在 WPF 应用程序中使用 SystemMediaTransportControls?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆