WPF:Textbox没有在onTextInput事件上触发

编程入门 行业动态 更新时间:2024-10-26 16:25:33
本文介绍了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事件上触发

本文发布于:2023-11-10 22:56:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1576689.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:事件   WPF   Textbox   onTextInput

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!