1

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel.

I am using NHibernate to decorate my property on the domain object as below.

private decimal _refurbishmentFee;
[Min(Value=0), NotNull]
public decimal RefurbishmentFee
{
    get { return _refurbishmentFee; }
    set 
    {
        if (_refurbishmentFee == value) return;
        _refurbishmentFee = value;
        OnPropertyChanged("RefurbishmentFee");
    }
}

The validation works fine if I put in a number less than 0, however if I put in alpha characters or a space then nothing happens, the application doesn't even fall into the setter.

Any help?

Thanks Faisal

1
  • Please post more details on how you are doing your validation. Is it ValidatesOnDataErrors in XAML? Commented Nov 9, 2009 at 16:24

1 Answer 1

1

Yes I am using ValidatesOnDataErrors in the XAML. Fortunately one of my colleagues resolved this issue last night so I thought I should put it on here in case someone else is in the same position.

To get the validation to occur in all cases you need to add ValidatesOnExceptions="True" as well as ValidatesOnDataErrors="True" in the XAML.

<Controls:NumberTextBox IsEnabled="{Binding IsEditable}"  Grid.Row="1" Grid.Column="3" Name="txtRefurbishmentFee">
    <TextBox.Text>
        <Binding Path="Entity.RefurbishmentFee" UpdateSourceTrigger="PropertyChanged" ValidatesOnExceptions="True" ValidatesOnDataErrors="True" />
    </TextBox.Text>
</Controls:NumberTextBox>

Then on the domain object use standard NHibernate validation decorators.

private decimal _refurbishmentFee;
[Min(Value=0)]
public decimal RefurbishmentFee
{
    get { return _refurbishmentFee; }
    set 
    {
        if (_refurbishmentFee == value) return;
        _refurbishmentFee = value;
        OnPropertyChanged("RefurbishmentFee");
    }
}

Thanks, Faisal

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.