tags:

views:

49

answers:

1

Hello experts:

I'm making a Wpf Application. I want to put validations on interger and character textboxes. How can i achive it? Please help me out guys .

Thanks in advance.

Shashank

+1  A: 

You can throw an Exception when values are out of range and use ValidationRules like this:

<TextBox>
    <TextBox.Text>
        <Binding Path="Number">
            <Binding.ValidationRules>
                <ExceptionValidationRule />
            </Binding.ValidationRules>
        </Binding>
    </TextBox.Text>
</TextBox>

More information can be found here: http://www.codeproject.com/KB/WPF/wpfvalidation.aspx

Update: In code behind you can do something like:

private int _Number;
public string Number
{
    get { return  _Number.ToString(); }
    set
    {
        if (!Int32.TryParse(value, out _Number))
        {
            throw new ApplicationException("Invalid integer number");
        }
    }
}
shayan
there is any method through code behind
Chunmun Tyagi
I edited the answer to include code behind. hopefully it is what you expected.
shayan