What are the defaults for Binding.Mode=Default for WPF controls?
Here's a way to find the Default mode supported by a DP -
.NET Reflector is your friend. With reflector, search for
TextBox
and look at the source for the static constructor (.cctor()
). Here, you will be able to find the code used for registering theTextProperty
DP:TextProperty = DependencyProperty.Register ( "Text", typeof(string), typeof(TextBox), new FrameworkPropertyMetadata ( string.Empty, FrameworkPropertyMetadataOptions.Journal | FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(TextBox.OnTextPropertyChanged), new CoerceValueCallback(TextBox.CoerceText), true, UpdateSourceTrigger.LostFocus ) );
Notice that a parameter is passed to the Register method indicating the default Binding Mode:
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault
. If you use reflector to look at the registration for TextBlock’s Text DP, you will see that no such value is passed, in which case we assume the binding is one way by default.
Taken from Bea Stollnitz's post : How can I update an explicit binding within a template?
Although having some kind of list of important DP's would be very helpful.
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, haveTwoWay
as their default Mode value. To figure out if the default isTwoWay
, look at the Dependency Property Information section of the property. If it saysBindsTwoWayByDefault
is set to true, then the default Mode value of the property isTwoWay
. To do it programmatically, get the property metadata of the property by callingGetMetadata
and then check the boolean value of theBindsTwoWayByDefault
property.
Source: https://web.archive.org/web/20100209025938/http://blogs.msdn.com/wpfsdk/archive/2006/10/19/wpf-basic-data-binding-faq.aspx
The safest way would be to always be explicit what kind of binding mode you want from a binding.