Note that there are some explanatory texts on larger screens.

plurals
  1. POINotifyPropertyChanged.PropertyChanged always NULL
    primarykey
    data
    text
    <p>I know I am doing something wrong here but what. Please have a look and point out my error.</p> <p>I will see "Peter" in my textbox but no "Jack" after the button click.</p> <p>My class</p> <pre><code>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)); } } } </code></pre> <p>}</p> <p>My XAML</p> <pre><code>&lt;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"&gt; &lt;Grid&gt; &lt;Grid.Resources&gt; &lt;app:Person x:Key="person"/&gt; &lt;/Grid.Resources&gt; &lt;TextBox Width="100" Height="26" Text="{Binding Source={StaticResource person}, Path=Name, Mode=TwoWay}" /&gt; &lt;Button Content="Button" Height="23" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" /&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>And my codebehind</p> <pre><code>public partial class MainWindow : Window { Person person; public MainWindow() { InitializeComponent(); person = new Person(); } private void button1_Click(object sender, RoutedEventArgs e) { person.SetName("Jack"); } } </code></pre> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload