Created
October 12, 2012 10:51
-
-
Save nseba/3878667 to your computer and use it in GitHub Desktop.
Xaml and view model for validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Grid> | |
<Grid.ColumnDefinitions> | |
<ColumnDefinition /> | |
<ColumnDefinition /> | |
<ColumnDefinition /> | |
</Grid.ColumnDefinitions> | |
<TextBlock Grid.Row="0" Style="{StaticResource FormLabelStyle}" Text="Name"/> | |
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Name, Mode=TwoWay}" common:Validation.Property="Name" common:Validation.ValidationPlaceholder="{Binding ElementName=NameValidation}" common:Validation.DataContext="{Binding}" /> | |
<View:ValidationResultPlaceholder Grid.Row="0" x:Name="NameValidation" Grid.Column="2" /> | |
</Grid> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.ComponentModel.DataAnnotations; | |
internal class SampleViewModel : ViewModel | |
{ | |
public SampleViewModel() | |
{ | |
ValidateObject(); | |
} | |
[Required] | |
[StringLength(250)] | |
public string Name | |
{ | |
get | |
{ | |
return name; | |
} | |
set | |
{ | |
SetPropertyAndValidate(() => name, x => name = x, value); | |
} | |
} | |
[Required] | |
[StringLength(250)] | |
public string Address | |
{ | |
get | |
{ | |
return address; | |
} | |
set | |
{ | |
SetPropertyAndValidate(() => address, x => address = x, value); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment