简体   繁体   中英

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

编译绑定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.

  • 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM