禁用专注于文本框的 Windows Phone 键盘 [英] Disabling keyboard of windows phone having focus on Textbox

查看:31
本文介绍了禁用专注于文本框的 Windows Phone 键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Windows Phone 的新手.

I am new in Windows Phone.

在我的应用程序中,我有一个文本框,其中光标首先会不断闪烁以进行输入.我有一个自定义拨号盘来接收用户的输入.所以我必须禁用 Windows Phone 键盘.

In my app I have a textbox where cursor will continuously blink for input at first. I have a custom dialpad to take input from users. So I have to disable the Windows Phone Keyboard.

在网上搜索后,大部分解决方案是将焦点从文本框中移开以隐藏键盘.

After searching online, most of the solution is based on removing the focus from textbox to hide the keyboard.

就我而言,它不会发生,因为键盘会立即弹出并隐藏.

In my case, its not happening since keyboard pops up and hide instantly.

任何帮助将不胜感激.

另一件事:我还需要光标在文本框中闪烁.

推荐答案

一种解决方法可能是根本不使用 TextBox.相反,您可以使用一个简单的 TextBlock,然后点击 TextBlock,打开您的自定义键盘.您可以切换键盘的可见性以隐藏/取消隐藏它.按下键盘上的按键,更新 TextBlock 的文本.

One workaround could be to not use TextBox at all. Instead, you can use a simple TextBlock and on tap on the TextBlock, open your custom keypad. You can probably toggle visibility of the keypad to hide/unhide it. on key press of the keypad, update the text of the TextBlock.

为此添加示例代码(还有游标实现)

EDIT : Adding a sample code for this (with cursor implementation as well)

用于我的自定义 TextBox 实现的 Xaml :

Xaml for my custom TextBox implementation :

<Border x:Name="brdTextBox" Background="White" BorderBrush="Blue" HorizontalAlignment="Stretch" Height="100"
                Margin="10">
                <StackPanel Orientation="Horizontal">
                    <TextBlock x:Name="txtEnterText" FontSize="28" Foreground="Black" Margin="0"></TextBlock>
                    <TextBlock x:Name="txtCursor" FontSize="28" Foreground="Black" Text="|" Margin="0"></TextBlock>
                </StackPanel>
            </Border>

后面的示例代码,它使用计时器来控制光标的滴答声:

A sample code behind, that uses timer to control the tick of the cursor :

Timer timer = new Timer((obj) => 
        {
            Dispatcher pageDispatcher = obj as Dispatcher;

            pageDispatcher.BeginInvoke(() => 
            {
                if (txtCursor.Text == "|")
                {
                    txtCursor.Text = "";
                }
                else
                {
                    txtCursor.Text = "|";
                }
            });

        }, this.Dispatcher, 1000, 1000);

此后,您可能可以在边框点击时调出键盘,并在键盘的按键事件中填充文本块.您可以调整计时器持续时间和间隔,以实现与实际光标的相似度.

After this, you can probably bring up your keypad on border tap, and on key event of the keypad, fill up the textblock. You can tweak the timer duration and intervals to achieve a close resemblance to the actual cursor.

希望有帮助.

这篇关于禁用专注于文本框的 Windows Phone 键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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