WPF MaskedTextBox所需的值 [英] WPF MaskedTextBox required value
本文介绍了WPF MaskedTextBox所需的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
This is my masked textbox from the WPF Extended Toolkit
<toolkit:MaskedTextBox Name="MaskedtxtTaxId" Mask="00-0000000" />
我不希望用户输入不完整的值,例如45-781 ____
但它可以像__-一样空_______
我需要强制用户输入所有9位数字或将其留空。
我可以用MaskedTextBox完成吗?
谢谢。
I don''t want the user to enter incomplete value eg 45-781____
but it can be empty like __-_______
I need to force the user to enter all 9 digits or leave it empty.
Can I accomplish that with the MaskedTextBox?
Thank you.
推荐答案
试试这个。
try this.
private void MaskedtxtTaxId_LostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
if (((MaskedTextBox)sender).MaskedTextProvider.AssignedEditPositionCount < ((MaskedTextBox)sender).MaskedTextProvider.AvailableEditPositionCount)
{
System.Windows.MessageBox.Show("Not valid");
/// do something
}
}
您需要检查在MasketTextBox中输入的值的长度。
类似
的东西
You need to check the Length of Value entered in the MasketTextBox.
Something like
If ( MaskedtxtTaxId.Value.Length < 9 and MaskedtxtTaxId.Value.Length > 0 ) Then
'display message "Value entered cannot be incomplete"
End if
var vPromptCharCount = MaskedtxtTaxId.Text.Count(x => x == '_');
if (count > 0 && count < 9)
{
//invalid
}
这篇关于WPF MaskedTextBox所需的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文