Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy doesn't the INotifyPropertyChanged work?
    text
    copied!<p>I used a Multibinding to bind some properties and use the INotifyPropertyChanged interface to notify these properties'changes.But sadly,it seems that the INotifyPropertyChanged didn't work. The PropertyChangedEventHandler "PropertyChanged" was null all the time.</p> <p>Questions:</p> <p>A. Could you please tell me why the event is null?In my mind,there should be a default method for the event PropertyChangedEventHandler,am I wrong?(Resolved,thanks!)</p> <p>B. Just like some friends said,I tried again without using the INotifyPropertyChanged.But the target's property's value seems to be not changed...</p> <hr> <ol> <li><p>Properties</p> <pre><code>public static readonly DependencyProperty LeftOffsetProperty = DependencyProperty.Register("LeftOffset", typeof(double), typeof(NetworkTaskLable), new FrameworkPropertyMetadata(0d, FrameworkPropertyMetadataOptions.AffectsRender)); public static readonly DependencyProperty TopOffsetProperty = DependencyProperty.Register("TopOffset", typeof(double), typeof(NetworkTaskLable), new FrameworkPropertyMetadata(0d, FrameworkPropertyMetadataOptions.AffectsRender)); public double LeftOffset { get { return (double)GetValue(LeftOffsetProperty); } set { SetValue(LeftOffsetProperty, value); } } public double TopOffset { get { return (double)GetValue(TopOffsetProperty); } set { SetValue(TopOffsetProperty, value); } } </code></pre></li> <li><p>Multibinding (It seems work well.By using the converter to calculate a location which is affected by "TopOffset" and "LeftOffset")</p> <pre><code>var multibinding = new MultiBinding() { Converter = new BeginAndStartDateToLeftConverter_NetworkTaskLable(), ConverterParameter = NetworkView }; multibinding.Bindings.Add(new Binding("Start")); multibinding.Bindings.Add(new Binding("StartDate") { Source = NetworkView }); multibinding.Bindings.Add(new Binding("LeftOffset") { Source = this }); MainCanvas.SetBinding(LeftProperty, multibinding); </code></pre></li> <li><p>INotifyPropertyChanged</p> <pre><code>public event PropertyChangedEventHandler PropertyChanged; public void CallPropertyChanged(string PropertyName) { if (PropertyChanged != null)//It seems to be null all the time!!!And the properties'changes were never notified!!! PropertyChanged(this, new PropertyChangedEventArgs(PropertyName)); } </code></pre></li> <li><p>Notify the change </p> <pre><code>SetValue(LeftOffsetProperty, moveAdorner.LeftOffset); CallPropertyChanged("LeftOffset"); SetValue(TopOffsetProperty, moveAdorner.TopOffset); CallPropertyChanged("TopOffset"); </code></pre></li> </ol>
 

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