DataAnnotations: if (valid) => change Property
Posted
by
Karl_Schuhmann
on Stack Overflow
See other posts from Stack Overflow
or by Karl_Schuhmann
Published on 2012-12-06T10:31:10Z
Indexed on
2012/12/06
11:05 UTC
Read the original article
Hit count: 210
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
© Stack Overflow or respective owner