Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to display a message whenever an user enters a value that is not a positive integer in the TextBox. My current TextBox is bound to an Integer Type. The TxtBox Bordder turns red whenever the User enters a Non -Integer value. But it does not change if a negative value is enetered. I would appreciate some help so as to how to display a message the moment the user enters a value that not a positive integer.

Here is my code


View:
<TextBox Text="{Binding NumberofDays,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" Height="23" HorizontalAlignment="Left" Margin="251,30,0,0" Name="textBox1" VerticalAlignment="Top" Width="31" />


ViewModel:
private int numberofDays = 0;

public int NumberofDays
        {
            get
            {
                return this.numberofDays ;
            }
            set
            {
                this.numberofDays = value;
                base.OnPropertyChanged("NumberofDays");
            }
        }
Posted
Comments
Thomas Duwe 3-Apr-13 4:01am    
How do you achive that the border turns red?
A good overview/introduction to validation you can find here:
http://www.codeproject.com/Articles/15239/Validation-in-Windows-Presentation-Foundation

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