x:Bind 与经典的 Binding 相比如何,尽可能简洁? [英] How does x:Bind compare with the classical Binding, put as concisely as possible?

查看:19
本文介绍了x:Bind 与经典的 Binding 相比如何,尽可能简洁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编译后的绑定 x:Bind 与 经典 绑定有什么不同,尽量简明扼要?

How is the compiled binding, x:Bind, different from the classical Binding, put as concisely as possible?

推荐答案

  • 经典绑定相比,您不能将以下绑定属性与 x:Bind 一起使用:ElementNameRelativeSourceSourceUpdateSourceTrigger.嗯,这几乎总结了 x:Bind 的局限性,但是 x:Bind 本身就很强大——值得注意的是编译绑定 从而提高性能.x:Bind 的军械库中另一个强大的东西,请参见最后一个要点.

    • Compared with the classical binding you cannot use the following binding attributes with x:Bind: ElementName, RelativeSource, Source and UpdateSourceTrigger. Well, that almost sums up the limitations of x:Bind but x:Bind is powerful in its own right -- the notable one being compiled binding and hence the performance gain as a result. See last bullet point for another powerful thing in x:Bind's armory.

      要始终记住的一个重要点:x:Bind 的数据上下文是代码隐藏类.要将 x:Bind 引导到 ViewModel 类,只需使用页面 DataContext 的 ViewModel 对象引用作为前缀.

      One important point to always remember: the data context of x:Bind is the code-behind class. To steer x:Bind to a ViewModel class, just prefix with the ViewModel object reference for page DataContext.

      另一点要记住的是,默认绑定模式是OneTime,而OneWayTwoWay 模式也可用.如果绑定似乎不起作用,则绑定可能处于默认模式并超过 OneTime 触发器.为避免此类事故,请明确定义绑定模式.

      Another point to remember is that the default binding Mode is OneTime while OneWay and TwoWay modes are also available. If a binding doesn't appear to be working, perhaps the binding is in default mode and past the OneTime trigger. To avoid such mishaps, define the binding Mode explicitly.

      我最喜欢的 -- 使用 x:Bind 绑定事件 -- 现在您可以轻松实现事件到方法模式.在 XAML 中,忘记 Tapped="MyTapHandlerInCodeBehind" 代码并开始使用 x:Bind 变体 Tapped="{x:Bind ViewModel.MyTapHandlerInViewModel}".一个小缺点是您不能像使用 经典 事件处理程序那样传递 Parameter,但这不是常见用例,并且存在替代方案.

      My favorite -- binding for events using x:Bind -- now you can easily implement event-to-method pattern. In XAML, forget the Tapped="MyTapHandlerInCodeBehind" code and start using the x:Bind variant Tapped="{x:Bind ViewModel.MyTapHandlerInViewModel}". One minor downside though is you cannot pass Parameter as with the classical event handler, but this is not common use case and an alternative exists.

      这篇关于x:Bind 与经典的 Binding 相比如何,尽可能简洁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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