DataAnnotations: if (valid) => change Property
- by Karl_Schuhmann
hi i'm googling around about this problem but i didn't find any usfull about this.
I want to deni the set of an property if the Validation per DataAnnotations fails
Could you please tell me what i miss in my code?
Model Codesnip
private string _firstname;
public string Firstname
{
get { return _firstname; }
set
{
_firstname = value;
RaisePropertyChanged(() => Reg(() => Firstname));
}
}
ViewModel Codesnip
[Required]
[RegularExpression(@"^[a-zA-ZäöüßÄÖÜß''-'\s]{2,40}$")]
public string Name
{
get { return currentperson.Name; }
set
{
currentperson.Name = value;
RaisePropertyChanged(() => Reg(() => Name));
}
}
View Codesnip
<TextBox HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" Text="{Binding Firstname,UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"/>
any help would be greatly appreciated