WPF:Textbox没有在onTextInput事件上触发 [英] WPF: Textbox not firing onTextInput event

查看:736
本文介绍了WPF:Textbox没有在onTextInput事件上触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以基本上,我有一堆用户可以填写的文本框。我有一个按钮,我想保持禁用,直到所有的文本框中都输入了文本。以下是我使用的示例XAML TextBox:

So basically, I have a bunch of TextBoxes that the user gets to fill out. I've got a button that I want to keep disabled until all the TextBoxes have had text entered in them. Here is a sample XAML TextBox that I'm using:

<TextBox Name="DelayedRecallScore" TextInput="CheckTextBoxFilled" Width="24" />

这里是我试图触发的功能:

And here is the function that I'm trying to trigger:

  //Disables the OK button until all score textboxes have content
    private void CheckTextBoxFilled(object sender, RoutedEventArgs e)
    {
        /*
        foreach (TextBox scorebox in TextBoxList)
        {
            if (string.IsNullOrEmpty(scorebox.Text))
            {
                Ok_Button.IsEnabled = false;
                return;
            }
        }
        Ok_Button.IsEnabled = true;
         */
        MessageBox.Show("THIS MAKES NO SENSE");
    }

当TextInput应该被触发时,MessageBox不显示。作为一个实验,我试图在PreviewTextInput上触发CheckTextBoxFilled(),它工作得很好,这意味着无论什么原因,该函数都没有被调用。我也有一个由PreviewTextInput触发的验证功能,它的工作原理是。起初我以为PreviewTextInput可能会干扰TextInput,所以我把PreviewTextInput从TextBox中删除,但是没有设法修复任何东西。我完全不知道为什么会发生这种情况,所以任何帮助将不胜感激。

The MessageBox is not showing up when TextInput should be getting triggered. As an experiment I tried triggering CheckTextBoxFilled() on PreviewTextInput, and it worked fine then, meaning that for whatever reason, the function just isn't getting called. I also have a validation function that is triggered by PreviewTextInput, which works as it should. At first I thought PreviewTextInput might somehow be interfering with TextInput, so I took PreviewTextInput off the TextBox, but that hasn't managed to fix anything. I'm completely befuddled by why this might happen, so any help would be appreciated.

推荐答案

您的处理程序 TextInput 事件不会被触发,因为 TextBox 正在处理事件。您可以尝试使用 TextChanged 事件,因为真的只是想知道什么时候添加或从 TextBox 中删除​​的字符。

Your handler for the TextInput event is not fired because the TextBox is handling the event. You could try using the TextChanged event instead, since really you just want to know when characters were added or removed from the TextBox.

这篇关于WPF:Textbox没有在onTextInput事件上触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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