日期:2014-05-17 浏览次数:20947 次
class Person
{
private int age;
public int Age
{
get { return age; }
set
{
if (value < 42)
throw new Exception("年龄太小");
else
age = value;
}
}
}
<Grid HorizontalAlignment="Left" Height="372" VerticalAlignment="Top" Width="467">
<Grid.Resources>
<local:Person x:Key="person1"></local:Person>
</Grid.Resources>
<TextBox HorizontalAlignment="Left" Height="23" Margin="87,173,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120">
<TextBox.Text>
<Binding Source="{StaticResource person1}" Path="Age" ValidatesOnExceptions ="True"/>
</TextBox.Text>
</TextBox>
</Grid>