.NET MAUI自定义输入按键活动处理

发布于 2025-02-11 21:14:24 字数 150 浏览 1 评论 0原文

有没有办法捕获.NET MAUI中的自定义输入控件的按键事件?例如,如果我有课程:

public class MyEntry : Entry
{

}

例如,我想每次用户在输入/聚焦条目时按他的关键字上的选项卡键执行操作。

Is there a way to capture keypress event for a custom entry control in .Net Maui? for example if i have the class:

public class MyEntry : Entry
{

}

And I want to perform an action everytime a user for example presses the tab key on his keyword while he is typing/focusing the entry.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

穿透光 2025-02-18 21:14:24

如果您可以使用条目识别的字符,则可以对您有用。

public class MyEntry : Entry
{
    public MyEntry()
    {
        TextChanged += MyEntry_TextChanged;
    }

    private void MyEntry_TextChanged(object sender, TextChangedEventArgs e)
    {
        if (e.OldTextValue != null
            && e.NewTextValue.Length <= e.OldTextValue.Length)
        {
            return;
        }

        if (e.NewTextValue.Last() == /*Insert your character here*/)
        {
            // Do your things
        }
    }
}

如果您在键盘上按键的键具有其他含义,而这些键 都不被认为是字符。

If you can use a character which is recognized by the Entry, this could work for you.

public class MyEntry : Entry
{
    public MyEntry()
    {
        TextChanged += MyEntry_TextChanged;
    }

    private void MyEntry_TextChanged(object sender, TextChangedEventArgs e)
    {
        if (e.OldTextValue != null
            && e.NewTextValue.Length <= e.OldTextValue.Length)
        {
            return;
        }

        if (e.NewTextValue.Last() == /*Insert your character here*/)
        {
            // Do your things
        }
    }
}

This won't work if the key you press on your keyboard has some other meaning which is not recognized as a character to write inside the Entry.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文