Difference between Binding and x:Bind

SeeuD1 picture SeeuD1 · May 23, 2016 · Viewed 12.6k times · Source

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?

Answer

Henk Holterman picture Henk Holterman · May 23, 2016

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