3

In WPF you could mark a DependencyProperty on a custom control as binding Mode=TwoWay by default using FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, but FrameworkPropertyMetadata seems to be missing in UWP. The UWP documentation on the {Binding} markup extension says that the default mode may change, but gives no indication on how to affect it.

Mode

Specifies the binding mode, as one of these values: "OneTime", "OneWay", or "TwoWay". These correspond to the constant names of the BindingMode enumeration. The default depends on the binding target but in most cases it is "OneWay". Note that this differs from the default for {x:Bind}, which is "OneTime".

How can you change the default binding mode for a UWP XAML Dependency Property on a custom control?

Community
  • 1
  • 1
Mitch
  • 21,223
  • 6
  • 63
  • 86
  • 1
    Related, but not duplicate: [How to change default mode of x:Bind?](https://stackoverflow.com/questions/41691478/how-to-change-default-mode-of-xbind) (refers to `{x:Bind}`, which is distinct from `{Binding}`) – Mitch Jan 11 '18 at 02:33

1 Answers1

2

The current UWP SDK doesn't have any support for affecting the default BindingMode for a DependencyProperty; that is only possible within WPF.

On UWP all {Binding} have BindingMode.OneWay as default, while {x:Bind} has BindingMode.OneTime

Pedro Lamas
  • 7,185
  • 4
  • 27
  • 35
  • Do you have a source for this? While it matches observed behavior, it does contradict the documentation. – Mitch Jan 12 '18 at 08:44
  • What documentation are you referring to? I can dig the links on the documents confirming this behavior, but here's a post I wrote a while back on this matter https://www.pedrolamas.com/2015/10/19/compiled-bindings-considerations/ – Pedro Lamas Jan 13 '18 at 10:05
  • The blog article you refer to seems to describe the `{x:Bind` markup extension. The [UWP documentation on the `{Binding}` markup extension](https://learn.microsoft.com/en-us/windows/uwp/xaml-platform/binding-markup-extension) says that the default mode may change. – Mitch Jan 13 '18 at 21:33
  • Fair point on that, but basically, the documentation is wrong!! I've contacted Microsoft and that will soon be corrected to match the information in my answer here. – Pedro Lamas Jan 15 '18 at 09:23