- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在移植我在 Xamarin Forms 中制作原型(prototype)的 Android 应用程序。我定位的设备具有必须触发应用程序中的操作的硬件按钮。在 Xamarin 中,我能够覆盖 ICallback.OnKeyDown(Keycode keyCode,KeyEvent e)
在Activity
.我没能在 MAUI 中找到任何等效项。我期待 <InputBinding/>
像 WPF 或者可能是事件或重写 Element
.有什么办法可以做到这一点?甚至可能使用特定于 Android 的代码?
最佳答案
我找到的一个解决方案(仅适用于 Android)是这样的(从我对另一个问题的回答中复制:MAUI How to use KeyEvent.Callback in an Android app):
定义一个界面以在您想要对物理键盘键做出“ react ”的页面中实现(可选 - 它用于区分您想要对键使用react的页面与不需要的页面)。示例:
#if ANDROID
using Android.Views;
#endif
namespace KeyboardTest
{
public interface IOnPageKeyDown
{
#if ANDROID
/// <summary>
/// Called when a key is pressed.
/// </summary>
/// <param name="keyCode">The code of pressed key.</param>
/// <param name="e">Description of the key event.</param>
/// <returns>
/// Return true to prevent this event from being propagated further,
/// or false to indicate that you have not handled this event and it should continue to be propagated.
/// </returns>
public bool OnPageKeyDown(Keycode keyCode, KeyEvent e);
#endif
}
}
为您想要对键使用react的每个页面实现此接口(interface)。示例:
#if ANDROID
using Android.Views;
#endif
// Your code here
namespace KeyboardTest
{
public partial class TestPage : ContentPage, IOnPageKeyDown
{
#if ANDROID
public bool OnPageKeyDown(Keycode keyCode, KeyEvent e)
{
switch (keyCode)
{
case Keycode.DpadUp:
// Your code here
return true;
case Keycode.DpadDown:
// Your code here
return true;
case Keycode.Enter:
// Your code here
return true;
default:
return false;
}
}
#endif
}
}
覆盖 Platforms/Android/MainActivity.cs 中的“OnKeyDown”。示例:
using Android.App;
using Android.Content.PM;
using Android.OS;
using Android.Runtime;
using Android.Views;
using AndroidX.Core.View;
namespace KeyboardTest;
// Your code here
public class MainActivity : MauiAppCompatActivity
{
// Your code here
public override bool OnKeyDown([GeneratedEnum] Keycode keyCode, KeyEvent e)
{
Page p = Shell.Current.CurrentPage;
if (p is IOnPageKeyDown)
{
bool handled = (p as IOnPageKeyDown).OnPageKeyDown(keyCode, e);
if (handled) return true;
else return base.OnKeyDown(keyCode, e);
}
else return base.OnKeyDown(keyCode, e);
}
}
希望对您有所帮助。
关于android - 在 .NET MAUI(特别是 Android)中 Hook 键盘事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71976350/
.NET MAUI 中的 Border 和 Frame 之间的功能区别是什么? 根据 documentation 的边界摘要是 The .NET Multi-platform App UI (.NET
我是桌面开发的新手,我正在尝试实现一个应用程序,它可以根据列表中的选定项目动态创建包含内容的选项卡。项目已添加到 TabBar.Items 集合,但我无法在应用程序窗口中看到它们( UWP WinUI
在我的 .NET MAUI 应用程序中,我使用 .NET MAUI 社区工具包中的 AvatarView 创建一个漂亮的圆形用户头像,这很容易做到。 我现在想在图像周围放置一个漂亮的边框,但我没有得到
我正在尝试在 .NET MAUI 中实现平台特定的部分方法以获取数据库的连接字符串。 在“主应用程序”中: namespace TestApp.DL; public partial class Bas
是否有毛伊岛 map 控件。如果是这样,某处是否有教程。我不想使用第 3 方控件,我想使用 opensteetmap。我真的不想用谷歌地图。 最佳答案 不幸的是,当前 GA 版本的官方 map 功能已
我正在尝试导航到“TestView”页面,该页面位于 VisualStudio 解决方案的“Views”文件夹中。这里编译错误。 错误 XFC0000 无法解析类型“:TestView” AppShe
我正在使用AppShell在我的 .NET MAUI 应用程序中,场景如下: 我有Page1 , Page2和Page3定义为我的主选项卡 AppShell -- 见下文:
刚接触 .Net MAUI,正在将 CommunityToolkit.Mvvm 版本 8.0.0 与 Microsoft Visual Studio Community 2022(64 位)一起使用
我想使用.NET Maui创建一个新项目,在Microsoft教程中,他们说先决条件是最新的Visual Studio 2022 17.1预览版,在安装了.NET Maui的最后一个预览版本后,我从列
我基本上来自网络背景并尝试使用 .NET MAUI Blazor Hybrid。我在使用 .NET MAUI Window 开发期间遇到错误,但不确定如何调试它?我查看了所有类型的窗口,但在任何地方都
嘿,我怎么才能改变Win UI.Net Maui Picker上难看的外部边框呢?有什么办法可以禁用它吗?或者换个颜色?。还有,当你将鼠标悬停在选取器上,文本会改变颜色时,这个奇怪的错误是什么?
这是一个带有SearchBar和ListView的ContentPage。ListView正在更新为SearchBar中的用户类型。。问题是,当用户阅读ListView结果时,键盘不会自动关闭。请问,
Hey how can i change the ugly outer borders on win ui .net maui picker? Is there any way to disab
这是一个带有搜索栏和ListView的内容页面。当用户在搜索栏中键入内容时,ListView正在更新。。问题是,当用户阅读ListView结果时,键盘不会自动关闭。请问,谁知道怎么做,如果我们希望键盘
我有一个Model类Person,它有一些字符串属性。在用户界面中,当按下按钮时,在ViewModel类中有一些输入字段执行以下操作:。使用填充对象属性的字段中的值创建Person对象。将Person
我有一个Model类Person,它有一些字符串属性。在用户界面中,当按下按钮时,在ViewModel类中有一些输入字段执行以下操作:。使用填充对象属性的字段中的值创建Person对象。将Person
I'm trying to write a media player in.Net MAUI with the new MediaElement, and so far everything s
@ 目录 创建页面元素 创建可绑定对象 创建绑定服务类 拖拽(Drag) 拖拽悬停,经
前言 笔者之前在公司搭建过一套生产管理系统,该系统要求能和硬件进行串口通信,同时又要方便后台进行信息查询。笔者给出的解决方案就是: MAUI + Blazor ,这样只需要提供一套UI,就
目录 前言 准备材料 审核流程 测试报告 隐私测试报告 隐私行为数据 其他问
我是一名优秀的程序员,十分优秀!