hgktzq
Last Updated: February 25, 2016
·
1.728K
· keboo

Default two way binding

By default when binding to a custom dependency property, the binding mode will default to OneWay.

The typical dependency property signature looks like this:

public static readonly DependencyProperty MyCustomFooProperty =
    DependencyProperty.Register("MyCustomFoo", typeof (object), typeof (MainWindow), 
    new PropertyMetadata(default(object)));

public object MyCustomFoo
{
    get { return GetValue(MyCustomFooProperty); }
    set { SetValue(MyCustomFooProperty, value); }
}

To make bindings on this dependency property default to TwoWay, the following change is needed:

public static readonly DependencyProperty MyCustomFooProperty =
    DependencyProperty.Register("MyCustomFoo", typeof(object), typeof(MainWindow),
    new FrameworkPropertyMetadata(default(object), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); public object MyCustomFoo { get { return GetValue(MyCustomFooProperty); } set { SetValue(MyCustomFooProperty, value); } }

Source: http://dotnetgeek.tumblr.com/post/33613680790/default-two-way-binding

Say Thanks
Respond

1 Response
Add your response

18737
None

Nice!

over 1 year ago ·