Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a TextBox Bound to a Double type variable.

C#
<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.

C#
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
Posted

1 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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900