A ‘Binding’ can only be set on a DependencyProperty of a DependencyObject

As a side note, it is also worth noting that you will get these binding errors if you copy and paste between objects and forget to change the second typeof(Object) statement. I couldn’t figure out for a good hour why I was getting this error as everything appeared to be defined and correct. I’d moved … Read more

What are the defaults for Binding.Mode=Default for WPF controls?

Similar to UpdateSourceTrigger, the default value for the Mode property varies for each property. User-editable properties such as TextBox.Text, ComboBox.Text, MenuItem.IsChecked, etc, have TwoWay as their default Mode value. To figure out if the default is TwoWay, look at the Dependency Property Information section of the property. If it says BindsTwoWayByDefault is set to true, … Read more

How do You Create a Read-Only Dependency Property?

It’s easy, actually (via RegisterReadOnly): public class OwnerClass : DependencyObject // or DependencyObject inheritor { private static readonly DependencyPropertyKey ReadOnlyPropPropertyKey = DependencyProperty.RegisterReadOnly( nameof(ReadOnlyProp), typeof(int), typeof(OwnerClass), new FrameworkPropertyMetadata(default(int), FrameworkPropertyMetadataOptions.None)); public static readonly DependencyProperty ReadOnlyPropProperty = ReadOnlyPropPropertyKey.DependencyProperty; public int ReadOnlyProp { get { return (int)GetValue(ReadOnlyPropProperty); } protected set { SetValue(ReadOnlyPropPropertyKey, value); } } //your other code here … Read more

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

What’s the difference between a dependency property and an attached property in WPF?

Attached properties are a type of dependency property. The difference is in how they’re used. With an attached property, the property is defined on a class that isn’t the same class for which it’s being used. This is usually used for layout. Good examples are Panel.ZIndex or Grid.Row – you apply this to a control … Read more

What is a dependency property?

The only explanation I found helpful and well written is this one: http://www.wpftutorial.net/dependencyproperties.html Basically, DependencyProperties differ from regular properties in that they’re not just setters / getters for fields in the class, but they retrieve their actual values dynamically during runtime. The SetValue() method of DPs is pretty straightforward and sets the local value of … 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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)