如何从 DeviceInformation.FindAllAsync 结果中找出当前正在使用的显示设备进行投影
Posted
技术标签:
【中文标题】如何从 DeviceInformation.FindAllAsync 结果中找出当前正在使用的显示设备进行投影【英文标题】:How to find out currently using display device from DeviceInformation.FindAllAsync results for Projection 【发布时间】:2021-10-27 21:34:00 【问题描述】:我正在尝试找出用户当前用作计算机/笔记本电脑主显示器的显示器,以便我可以向用户显示可用的显示器,它支持投影并且可以使用 ProjectionManager
@ 987654321@。请记住,这是针对 UWP 应用程序的。
DeviceInformationCollection displayDevices = DeviceInformation.FindAllAsync(ProjectionManager.GetDeviceSelector());
DeviceInformation.FindAllAsync(...)
返回DeviceInformation
的集合。 DeviceInformation
具有 Pairing
属性,但始终返回 false(即使对于主显示)。
是否有任何其他 API 可用于获取主显示器/当前正在使用的显示器?
例如:
-
我从
DeviceInformation
获得的DeviceId
可用于BluetoothDevice.FromIdAsync(String DeviceId)
用于蓝牙特定的API 要求,例如-Connected
状态。
能否获取当前使用的显示ID DeviceId
并与集合中的DeviceInformation.DeviceId
匹配以丢弃它?
ProjectionManager
有类似的功能吗?我经历了official docs,也经历了github examples,找不到合适的东西。所以,需要帮助。谢谢。
【问题讨论】:
Pairing
告诉您设备是否通过蓝牙/WiFi 配对(连接)。它与主显示器无关。它会告诉您无线鼠标、打印机或投影仪是否已配对
感谢您的指出。这只是我提到的一个观察。但这不是这里的问题。
【参考方案1】:
是否有任何其他 API 可用于获取主显示器/当前正在使用的显示器?
ProjectionManager
没有这样的 api 可以检测到主显示器。但你可以使用DisplayRegion
来检测它。
如果你想获得主要,你可以检查当前的 DisplayRegion WorkAreaOffset
是否是 0,0
。并且它有设备id属性,你可以用它来获取匹配的监视器。
IReadOnlyList<DisplayRegion> displayRegions = ApplicationView.GetForCurrentView().WindowingEnvironment.GetDisplayRegions();
// count all the DisplayRegions that are marked as available to the app for use.
foreach (DisplayRegion displayregion in displayRegions)
if (displayregion.IsVisible)
Debug.WriteLine(displayregion.WorkAreaOffset);
用于获取当前使用的显示。
ApplicationView.GetForCurrentView().GetDisplayRegions()[0]
更多代码请参考官方code sample。
【讨论】:
非常感谢您的回答和官方代码参考。将尽快检查并让您知道我的反馈。以上是关于如何从 DeviceInformation.FindAllAsync 结果中找出当前正在使用的显示设备进行投影的主要内容,如果未能解决你的问题,请参考以下文章
如何将数据从回收器适配器发送到片段 |如何从 recyclerview 适配器调用片段函数
如何从服务器获取和设置 android 中的 API(从服务器获取 int 值)?如何绑定和实现这个