I have an object like this:
public class Person { public string Name { get; set; } public Person() { Name = "Godspeed"; } }
Then I have three text fields and a button in XAML:
<Window x:Class="WpfApplication19.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApplication19" Title="MainWindow" Height="350" Width="525"> <Window.DataContext> <local:Person /> </Window.DataContext> <StackPanel> <TextBox Text="{Binding Name,UpdateSourceTrigger=PropertyChanged}" /> <TextBox Text="{Binding Name,UpdateSourceTrigger=PropertyChanged}" /> <TextBox Text="{Binding Name,UpdateSourceTrigger=PropertyChanged}" /> <Button Click="Button_Click">Click</Button> </StackPanel> </Window>
The strange thing is that the "Face" entity does not implement INotifyPropertyChanged, but when one text field is changed, it changes the source (Person object), but we did not raise the event with the changed property, but the other two text fields automatically change.
When the button is clicked, we update the source directly using the code, for example:
((Person)DataContext).Name = "Godspeed";
It is not updated. Therefore, I believe that if the Person class implements INotifyPropertyChanged, this behavior is normal, but now the class does not implement the interface, but it also updates the interface. Please tell me the reason if you have any clue. Thanks.
source share