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

后端 未结 3 1234
情话喂你
情话喂你 2020-12-28 11:37

In WPF Binding.Mode, when selecting Default, it depends in the property being binded.

I am looking for some list or some convention or any information for the defaul

3条回答
  •  不思量自难忘°
    2020-12-28 12:08

    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 the TextProperty 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.

提交回复
热议问题