绑定和 x:Bind 的区别 [英] Difference between Binding and x:Bind

查看:30
本文介绍了绑定和 x:Bind 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 UWP 中使用什么,Bindingx:Bind 以及它们之间的区别是什么?

What to use in UWP, Binding or x:Bind and what is the difference between them?

因为我看到很多帖子都在使用 Binding 而我在 UWP 中只使用 x:Bind 绑定.

Because I see a lot of posts where people use Binding and I only Bind with x:Bind in UWP.

在 MSDN 主页上,它只说由 {x:Bind}{Binding} 创建的绑定对象在功能上基本相同."并且 x:Bind 更快.

At the MSDN Homepage it only says that "the binding objects created by {x:Bind} and {Binding} are largely functionally equivalent." and that x:Bind is faster.

但是它们之间有什么区别?

因为在很大程度上功能上等效"并不意味着等效.

Because "largely functionally equivalent" does not mean equivalent.

来自我的引用的链接:MSDN

所以我的问题是:

在 UWP 中使用 Binding 或 x:Bind 有什么区别?

What is the difference in using Binding or x:Bind in UWP?

推荐答案

以下可能不完整,但一些主要区别是

The following is probably not complete, but some of the major differences are

  • 旧样式{Binding }

  • 绑定到 DataContext
  • 绑定到属性名称,对实际源类型灵活
  • 新样式{x:Bind }

  • 绑定到框架元素(代码隐藏类)
  • 需要在编译时修复所有类型
  • 默认为更节俭的 OneTime 模式

从 build 14393 开始{x:Bind } 支持:

  • 直接 BooleanToVisibility 绑定,没有 ValueConverter
  • 扩展的函数绑定
  • 铸造
  • 字典索引器

较新的 {x:Bind } 在运行时稍微快一些,但同样重要的是它会为错误的绑定提供编译器错误.使用 {Binding},在大多数情况下您只会看到一个空的 Control.

The newer {x:Bind } is a little faster at runtime but just as important it will give compiler errors for erroneous bindings. With {Binding } you would just see an empty Control in most cases.

对于深入比较结帐:{x:Bind} 和 {Binding} 功能比较

这篇关于绑定和 x:Bind 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆