xaml - 如何更改 x :Bind? 的默认模式

标签 xaml uwp windows-10 xbind

我不知道他们为什么决定为 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捆绑。 OneWayTwoWay绑定(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/

相关文章:

c# - 绑定(bind)到属性

C# UWP XAML 动画

html - Microsoft Edge播放曾经是下载的音频文件

hadoop - 在 Windows 10 上安装 Hadoop 2.7.2 时出错

c# - 根据内容调整新窗口的大小,并相对于主窗口居中

visual-studio-2010 - Caliburn.Micro 将如何处理能够在 Silverlight 5 中设置断点的问题

sqlite - Xamarin Forms UWP Sqlite 连接,无法加载文件或程序集 SQLite-net

xaml - Binding和x的区别 :Bind

安卓 SDK。无法启动 AVD

c# - 禁用按钮上的 "IsEnabled=false"颜色更改?