Kay*_*Ell 12 wpf events textbox textinput
所以基本上,我有一堆用户可以填写的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,但是还没有设法解决任何问题.对于为什么会发生这种情况我完全糊涂了,所以任何帮助都会受到赞赏.
And*_*ndy 15
您的TextInput事件处理程序未被触发,因为它TextBox正在处理事件.您可以尝试使用TextChanged事件,因为实际上您只是想知道何时添加或删除字符TextBox.
小智 7
InitializeComponent();
textbox.AddHandler(TextBox.TextInputEvent,
new TextCompositionEventHandler(TextBox_TextInput_1),
true);
Run Code Online (Sandbox Code Playgroud)