у меня есть:
public class Person : INotifyPropertyChanged
{
private string _name;
public int Age { get; set; }
public string Name
{
get { return _name; }
set
{
if (!String.IsNullOrEmpty(_name))
{
if (String.IsNullOrEmpty(value))
{
throw new Exception("name couldn't be null");
}
else if ((_name.Equals(value) != true))
{
if (!String.IsNullOrEmpty(value))
{
throw new Exception("name couldn't be null");
}
else
{
InvokePropertyChanged("_name");
}
_name = value;
}
}
else if (String.IsNullOrEmpty(value))
{
throw new Exception("name couldn't be null");
}
else
{
_name = value;
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void InvokePropertyChanged(string propertyName)
{
var e = new PropertyChangedEventArgs(propertyName);
PropertyChangedEventHandler changed = PropertyChanged;
if (changed != null) changed(this, e);
}
>
<Grid>
<StackPanel>
<TextBox Name="tbName" Text="{Binding Path=Name, Mode=TwoWay}"></TextBox>
<TextBox Name="tbOther" Text="Come in"></TextBox>
</StackPanel>
</Grid>
и
public UserControl1()
{
InitializeComponent();
Person person = new Person();
person.Name = "Patrick";
this.DataContext = person;
}
Почему, когда я отлаживаю и вхожу в строку:
выбросить новое исключение («имя не может быть нулевым»);
исключение не отображается.