小编Kay*_*Ell的帖子

WPF:文本框未触发onTextInput事件

所以基本上,我有一堆用户可以填写的TextBox.我有一个按钮,我想要保持禁用状态,直到所有TextBox都输入了文本.这是我正在使用的示例XAML TextBox:

<TextBox Name="DelayedRecallScore" TextInput="CheckTextBoxFilled" Width="24" />
Run Code Online (Sandbox Code Playgroud)

这是我试图触发的功能:

  //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");
    }
Run Code Online (Sandbox Code Playgroud)

应该触发TextInput时,MessageBox不会显示.作为一个实验,我尝试在PreviewTextInput上触发CheckTextBoxFilled(),然后它运行正常,这意味着无论出于何种原因,函数都没有被调用.我还有一个由PreviewTextInput触发的验证函数,它可以正常工作.起初我以为PreviewTextInput可能会以某种方式干扰TextInput,所以我从TextBox中取出了PreviewTextInput,但是还没有设法解决任何问题.对于为什么会发生这种情况我完全糊涂了,所以任何帮助都会受到赞赏.

wpf events textbox textinput

12
推荐指数
2
解决办法
2万
查看次数

标签 统计

events ×1

textbox ×1

textinput ×1

wpf ×1