[英]How to set max integer value as TextBox value
I have a TextBox with regex validation. 我有一个带有正则表达式验证的TextBox。 It will be for counting days in a year,so I wanna set max value to 366. I wrote LINQ for it,but somehow It always get back false. 它将用于计算一年中的天数,因此我想将最大值设置为366。我为此编写了LINQ,但无论如何它总是返回false。 If I exceed It and my validation turn to false,I want the program to set the max value automatically in my false statement. 如果我超过了它,并且我的验证变为false,我希望程序在我的false语句中自动设置最大值。 My code: 我的代码:
XAML: XAML:
<TextBox PreviewTextInput="Num" MaxLength="3" HorizontalAlignment="Left" Height="25" Margin="300,130,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="140" Name="tNum" TextChanged="tbNum_TextChanged"/>
Please help me :) 请帮我 :)
You can use the key down event and check if the content of your textbox + the key that was pressed is more than 365 您可以使用键按下事件并检查文本框的内容+所按下的键是否大于365
private void TextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
//write your validating
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.