Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
822 views
in Technique[技术] by (71.8m points)

xaml - Difference between Binding and x:Bind

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

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

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.

But what is the difference between them?

Because "largely functionally equivalent" does not mean equivalent.

The Link from my Quote: MSDN

So my Question is:

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

  • Old style {Binding }

    • binds to the DataContext
    • binds to a Property Name, flexible about the actual source type

  • New style {x:Bind }

    • binds to the Framework element (code-behind class)
    • needs all types fixed at compile time
    • defaults to the more frugal OneTime mode

And starting with build 14393, {x:Bind } supports:

  • direct BooleanToVisibility binding, without a ValueConverter
  • expanded Function binding
  • casting
  • dictionary indexers

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.

For in-depth comparison checkout: {x:Bind} and {Binding} feature comparison


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...