Silverlight data binding not listening for PropertyChanged event

Can someone please explain to me what's going on here? I am creating a binding in code.

Target - UserControl
The target property is a boolean DependencyProperty
The source object is a FrameworkElement and implements INotifyPropertyChanged The source property is of type ObservableCollection

What's happening:

  • Binding is generated in code, BindingExpressionBase result looks great, OneWay mode, target is set correctly (at this time)

    Binding b = new binding (); b.Path = "SourceProperty",
    b.Source = SourceObject;
    BindingExpressionBase e = this.SetBinding (TargetProperty, b);

  • The source property is then changed as a result of another data binding. UserControl is trying to fire the PropertyChanged event.

  • .... but nobody is listening. PropertyChanged is null.

I'm pretty sure nothing is assigned to the target property, so it should still be bound. Why isn't the binding listening for the PropertyChanged event?

+1


source to share


2 answers


Ok, I found the answer myself. This is a bug in Silverlight.

Code that does the following



if (PropertyChanged != null)  
{  
    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));  
}  

      

should be directly above the class you are linking to, not from its ancestor. I used it inside the FirePropertyChanged () method in the base class and moved it to a derived class.

+2


source


For anyone experiencing this: make sure you implement INotifyPropertyChanged on your ViewModel !



0


source







All Articles