Note that there are some explanatory texts on larger screens.

plurals
  1. POINotifyPropertyChanged does not work when the property set to a same value for the second time
    text
    copied!<p>This is the code to reproduce this issue:</p> <p>xaml:</p> <pre><code>&lt;Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"&gt; &lt;Grid&gt; &lt;TextBox Text="{Binding Num, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"&gt;&lt;/TextBox&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>C#:</p> <pre><code>using System.ComponentModel; using System.Windows; namespace WpfApplication1 { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); this.DataContext = new Entity(); } } public class Entity : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; private double num; protected void OnPropertyChanged(string propertyName) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(propertyName)); } } public double Num { get { return num; } set { num = value; if (value &gt; 100) { num = 100; } OnPropertyChanged("Num"); } } } </code></pre> <p>}</p> <p>Now, if I run it, input 1, it's ok. Then input another 1, which makes it 11, it's still ok. And then input another more 1, which makes 111, now the validation will work and change the value to 100, and the UI will show 100. But then if I input more numbers, the UI will not change, it'll be 1001.</p> <p>I guess it has something to do with setting the property to the same value(100) for twice. But I have no idea how to fix it, by fix it, I mean to make the UI always follow the property value.</p> <p>Thanks</p>
 

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