Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change default mode of x:Bind?

I don't know why they decided to set default value for Mode to OneTime But that's not what I want most of the time. It wasted my whole day in debugging.

Is there a way to set OneWay value as default for Mode of x:Bind ?

<!--This will not listen to future changes. it is OneTime by default-->
<TextBlock Text="{x:Bind Name}"/>

<!--We have to explicitly define Mode value-->
<TextBlock Text="{x:Bind Name, Mode=OneWay}"/>
like image 796
Blendester Avatar asked Jan 05 '23 17:01

Blendester


1 Answers

TL:DR: No it's not possible to change the binding mode on the built-in controls.

x:Bind together with a few other markup extensions like x:Phase were all added to increase performance. Keep in mind that UWP applications can run on desktops, but also on the smallest IoT devices, so performance is key.

First of all, x:Bind is a compiled binding. During compilation the XAML is converted to strongly typed code behind, which is faster than the runtime object inspection used by {Binding}.

Second, it's optimized for performance by itself, using OneTime binding. OneWay and TwoWay bindings requires infrastructure to watch and push back changes.

The binding object can optionally be configured to observe changes in the value of the data source property and refresh itself based on those changes. It can also optionally be configured to push changes in its own value back to the source property.

In the past everything used to be OneWay with {Binding}, implying a small performance hit on every single field, even those that had to be bound only once (because why would you bother changing to OneTime if it just works). Now you're forced to think which fields should be update-able and thus use more resources.

More info on x:Bind on MSDN.

like image 90
Bart Avatar answered Jan 22 '23 11:01

Bart