问题描述
我正在尝试为 Surface Duo 构建 Xamarin Forms 项目。项目运行,但不会同时使用两个屏幕。我按照 Xamarin for Surface Duo 的步骤操作 - 双屏 |微软文档:
-
更新了指向 SDK 的指针。
-
将
Xamarin.Forms.DualScreen.DualScreenService.Init(this);
添加到mainactivity.cs
。 -
修改了活动缩写以包括:
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.UiMode
。 -
在 Android 应用中包含 Xamarin.DuoSdk 包。
-
选定的
<build>
(Android 10.0 – API 29)
我下载了一些示例(Sketch 360 和双屏演示),但没有成功让它们同时使用两个屏幕。我运行了 Get 上发布的演示,并更新了软件包,但没有运气。我检查了模拟器中的手机设置,看看是否有启用两个屏幕的设置,但没有找到任何东西。模拟器输出中有一些错误、警告,但不知道如何修复。
模拟器输出
emulator: Silencing all qWarning(); use qCWarning(...) instead: QT_LOGGING_RULES=default.warning=false
Failed to open /qemu.conf,err: 2
emulator: INFO: QtLogger.cpp:68: Critical: UpdatelayeredWindowIndirect Failed for ptDst=(1283,327),size=(700x21),dirty=(700x108 0,0) (A device attached to the system is not functioning.) ((null):0,(null))
emulator: INFO: QtLogger.cpp:68: Critical: UpdatelayeredWindowIndirect Failed for ptDst=(1283,dirty=(700x21 0,(null))
emulator: INFO: QtLogger.cpp:68: Critical: Uncaught TypeError: Cannot read property 'update' of undefined (qrc:/html/js/location-mock-web-channel.js:130,(null))
构建输出
system.invalidCastException: Unable to cast object of type 'Mono.Debugger.soft.PointerValue' to type 'Mono.Debugger.soft.PrimitiveValue'.
system.invalidCastException: Unable to cast object of type 'Mono.Debugger.soft.PointerValue' to type 'Mono.Debugger.soft.PrimitiveValue'.
system.invalidCastException: Unable to cast object of type 'Mono.Debugger.soft.PointerValue' to type 'Mono.Debugger.soft.PrimitiveValue'.
02-06 20:34:52.574 W/libc ( 3873): Unable to set property "qemu.gles" to "1": connection Failed; errno=13 (Permission denied)
02-06 20:34:54.961 W/Openglrenderer( 3873): Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED,retrying without...
解决方法
如果您问的是如何让应用以编程方式使用两个屏幕,而不是用户在启动应用后执行操作,则无法做到。
请看这里的解释: https://docs.microsoft.com/en-us/dual-screen/introduction
当用户启动应用时,其核心窗口会最大化打开并占据单个屏幕的整个宽度和高度。
用户负责跨应用,这不是应用以编程方式进入的状态。
用户始终处于控制之中:为了避免给您的用户带来不可预测(或可能具有破坏性)的体验,应用不应在没有用户有意操作的情况下自动进入跨区状态。让用户决定。
,运行 Surface Duo Emulator for Visual Studio
以启动 Surface Duo 模拟器。如果您对模拟器有任何问题,可以使用以下链接进行故障排除。 https://docs.microsoft.com/en-us/dual-screen/xamarin/use-emulator?tabs=windows#update-the-pointer-to-your-android-sdk
通过 NuGet 安装包。 Xamarin.Forms.DualScreen
:https://www.nuget.org/packages/Xamarin.Forms.DualScreen
使用如下所示的 xaml。
<dualScreen:TwoPaneView>
<dualScreen:TwoPaneView.Pane1>
<StackLayout>
<Label Text="Pane1 Content" />
</StackLayout>
</dualScreen:TwoPaneView.Pane1>
<dualScreen:TwoPaneView.Pane2>
<StackLayout>
<Label Text="Pane2 Content" />
</StackLayout>
</dualScreen:TwoPaneView.Pane2>
</dualScreen:TwoPaneView>
使用模拟器 <build> (Android 10.0 – API 29)
运行项目