Свойство DataContext из UserControl является ключом к реализации mvvm, Person является вашей моделью и не должно быть открыто для просмотра, но через объект ViewModel.
public class PersonViewModel: INotifyPropertyChanged
{
public PersonViewModel()
{
/*You could initialize Person from data store or create new here but not necessary.
It depends on your requierements*/
Person = new Person();
}
private Person person;
public Person Person{
get {return person;}
set {
if (person != value){
person = value;
OnPropertyChanged()
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName]string propertyName = null)
{
var eventHandler = this.PropertyChanged;
if (eventHandler != null)
{
eventHandler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Затем в View (UserControl):
public partial class PersonRectangle : UserControl
{
public PersonRectangle()
{
InitializeComponent();
DataContext = new PersonViewModel();
}
}
Вы уже установили DataContext так вас может связать элементы управления видом на свойство Person, обратите внимание на использование Person имущества из ViewModel здесь:
<TextBox Text="{Binding Path=Person.Name, Mode=TwoWay}" />
Мои последние слова были бы предложить вам использовать структуру MVVM как Prism или Caliburn.Micro
EDIT:
Вы должны рассмотреть, чтобы выставить данные лица в качестве свойств, а не в публичных переменных, как у вас есть сейчас.