Listen to changes of dependency property

This method is definitely missing here: DependencyPropertyDescriptor .FromProperty(RadioButton.IsCheckedProperty, typeof(RadioButton)) .AddValueChanged(radioButton, (s,e) => { /* … */ }); Caution: Because DependencyPropertyDescriptor has a static list of all handlers in application every object referenced in those handlers will leak if the handler is not eventually removed. (It does not work like common events on instance objects.) Always … Read more

DependencyProperty getter/setter not being called

I would suggest not to use ObservableCollection as the type of an Items dependency property. The reason for having an ObservableCollection here (I guess) is to enable the UserControl to attach a CollectionChanged handler when the property value is assigned. But ObservableCollection is too specific. The approach in WPF (e.g. in ItemsControl.ItemsSource) is to define … Read more

DependencyProperty not triggered

The setter of your dependency property will not be called when the property is set in XAML. WPF will instead call the SetValue method directly. See MSDN XAML Loading and Dependency Properties for an explanation why the setter is not called. You would have to register a PropertyChangedCallback with property metadata.

XAML binding not working on dependency property?

The dependency property declaration must look like this: public static readonly DependencyProperty TestProperty = DependencyProperty.Register( nameof(Test), typeof(string), typeof(MyControl), new PropertyMetadata(“DEFAULT”)); public string Test { get { return (string)GetValue(TestProperty); } set { SetValue(TestProperty, value); } } The binding in the UserControl’s XAML must set the control instance as the source object, e.g. by setting the Bindings’s … Read more

INotifyPropertyChanged vs. DependencyProperty in ViewModel

Kent wrote an interesting blog about this topic: View Models: POCOs versus DependencyObjects. Short summary: DependencyObjects are not marked as serializable The DependencyObject class overrides and seals the Equals() and GetHashCode() methods A DependencyObject has thread affinity – it can only be accessed on the thread on which it was created I prefer the POCO … Read more