INotifyPropertyChanged.PropertyChanged всегда NULL

Я знаю, что делаю здесь что-то не так, но что? Пожалуйста, посмотрите и укажите на мою ошибку.

Я увижу «Питер» в текстовом поле, но не «Джек» после нажатия кнопки.

Мой класс

namespace App
{
    class Person : INotifyPropertyChanged
    {
        private string name;
        public String Name
        {
            get { return name; }
            set { name = value; OnPropertyChanged("Name"); }
        }
    public Person()
    {
        Name = "Peter";
    }

    public void SetName(string newname)
    {
        Name = newname;
    }

    public event PropertyChangedEventHandler PropertyChanged;

    private void OnPropertyChanged(string prop)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(prop));
        }
    }
}

}

Мой XAML

<Window x:Class="test.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:app="clr-namespace:App"
    Title="MainWindow" Height="400" Width="400">
<Grid>
    <Grid.Resources>
        <app:Person x:Key="person"/>
    </Grid.Resources>
    <TextBox  Width="100" Height="26" Text="{Binding Source={StaticResource person}, Path=Name, Mode=TwoWay}" />
    <Button Content="Button" Height="23"  Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
</Grid>

И мой код позади

public partial class MainWindow : Window
{
    Person person;

    public MainWindow()
    {
        InitializeComponent();

        person = new Person();       
    }

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        person.SetName("Jack");
    }
}

Спасибо.

5
задан Core-One 22 April 2011 в 10:09
поделиться