我不知道他们为什么决定为 Mode
设置默认值至OneTime
但这不是我大多数时候想要的。它浪费了我一整天的调试时间。
有没有办法设置OneWay
Mode
的默认值的 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}"/>
最佳答案
TL:DR: 不,无法更改内置控件的绑定(bind)模式。x:Bind
以及一些其他标记扩展,如 x:Phase
全部加起来增加性能 .请记住,UWP 应用程序可以在桌面上运行,也可以在最小的 IoT 设备上运行,因此性能是关键。
首先,x:Bind
是一个编译绑定(bind)。在编译期间,XAML 被转换为后面的强类型代码,这比 {Binding}
使用的运行时对象检查要快。 .
其次,它本身针对性能进行了优化,使用 OneTime
捆绑。 OneWay
和 TwoWay
绑定(bind)需要基础设施来监视和推回更改。
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.
过去一切都是
OneWay
与 {Binding}
,这意味着每个领域的性能都会受到很小的影响,即使是那些只需要绑定(bind)一次的领域(因为如果它可以正常工作,你为什么还要麻烦更改为 OneTime
)。现在你不得不考虑哪些字段应该是可更新的,从而使用更多的资源。有关 x 的更多信息:绑定(bind) MSDN .
关于xaml - 如何更改 x :Bind? 的默认模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41691478/