我的文本框内容被修剪。 [英] My Textbox content get trimmed.

查看:85
本文介绍了我的文本框内容被修剪。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个绑定到Double类型变量的TextBox。



< TextBox Text =   {Binding Path = OldRegCost,Mode = TwoWay,UpdateSourceTrigger = PropertyChanged} Grid.Row =   0 Grid.Column =   1高度=   25宽度=   50 Margin =   10,0,10,0 >  < /   TextBox  >  





In后面的代码我将文本框绑定到Double类型变量。



  private  ? _OldRegCost; 

public Double ? OldRegCost
{
get { return _OldRegCost; }
set
{
OldRegCost = value ;
RaisePropertyChanged( OldRegCost);
}
}





当用户尝试输入符号时(@,#,$,%, & etc)TextBox自动变成红色。

它还修剪输入的特殊字符。



因为我正在使用单独的验证代码背后的正则表达式:



1)在代码中是否有任何方法可以知道文本字段是否变为RED(输入的字符无效)



2)或者我可以删除RED效果并获取整个文本(带有无效字符)后面的代码。



请给我一个解决方案

解决方案

,%,&等)TextBox自动变成红色。

它还修剪输入的特殊字符。



因为我在使用Regex进行单独验证代码背后:



1)代码后面是否有任何方法可以知道文本字段是否变为RED(输入的字符无效)



2)或者我可以删除RED效果并将整个文本(带有无效字符)编码到后面。



请给我解决方案


问题正在发生,因为符号不是双倍的。因此,作为WPF一部分的错误处理会识别出您输入的内容无效并通过红色边框通知您。



为什么您希望能够在本质上是一个数字文本框中有字符?



如果你想要大量的文本然后绑定到文本属性而不是可以为空的双属性。

I have a TextBox Bound to a Double type variable.

<TextBox Text="{Binding Path=OldRegCost,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"  Grid.Row="0" Grid.Column="1" Height="25" Width="50" Margin="10,0,10,0"></TextBox>



In the code behind i binded the textbox to a Double type variable.

private Double? _OldRegCost;

public Double? OldRegCost
  {
     get { return _OldRegCost; }
     set
         {
            OldRegCost = value;
            RaisePropertyChanged("OldRegCost");
          }
  }



When the user try to enter a symbol (@,#,$,%,& etc) the TextBox automatically turns RED colour.
It also trims the entered special character.

Since am doing a separate validation using Regex in code behind:

1) Is there any way in code behind to know whether the text field turned RED (an invalid character entered)

2) or can i remove the RED effect and get the entire text (with invalid character) to code behind.

Please give me a solution

解决方案

,%,& etc) the TextBox automatically turns RED colour.
It also trims the entered special character.

Since am doing a separate validation using Regex in code behind:

1) Is there any way in code behind to know whether the text field turned RED (an invalid character entered)

2) or can i remove the RED effect and get the entire text (with invalid character) to code behind.

Please give me a solution


The issue is occurring because symbols are not valid double's. As a result the error handling that is part of WPF identifies that what you are typing is invalid and informs you via the red border.

Why do you want to be able to have "characters" in what in essence is a numerical text box?

If you want the whole lot of text then bind to a text property and not a nullable double property.


这篇关于我的文本框内容被修剪。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆