You're not setting the control to be bound to your person object from what I can see. As such, it shouldn't be attempting to set it and subsequently erroring.
When you put a break point in your getter, does it even get called?
You're not setting the control to be bound to your person object from what I can see. As such, it shouldn't be attempting to set it and subsequently erroring.
When you put a break point in your getter, does it even get called?
I think you want to assign the Person object to the control's DataContext:
public UserControl1()
{
InitializeComponent();
Person person = new Person();
person.Name = "Patrick";
this.DataContext = person;
}
You may also want to set ValidatesOnExceptions on your binding so that the UI will display the error template when an exception is thrown in the setter.
<TextBox Name="tbName" Text="{Binding Path=Name, Mode=TwoWay, ValidatesOnExceptions=True}"></TextBox>
Please see this other question, but basically the exception will be handled and suppressed by the Binding.
try doing this:
...
else if (String.IsNullOrEmpty(value))
{
try{
throw new Exception("name couldn't be null");
}
catch(Exception ex)
{
//Set Breakpoint Below
int x=0;
}
}
...
You will see that your code will come in the catch block, and the exception does get thrown. The handling of the exception however is upto you. The best way is already suggested by Quartermeister.
Otherwise based on your VS IDE settings, the exception gets suppressed, and you do not see an error on screen.