How does x:Bind compare with the classical Binding, put as concisely as possible?

邮差的信 提交于 2019-12-04 12:34:58
  • 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.

  • 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.

  • 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.

  • 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.

The classic binding uses reflection to get the properties values to bind. X:Bind creates a class at compile time for getting the values so the binding will be quicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!