0

In Windows 8.1, I can do this

<Grid Margin="8"
      VerticalAlignment="Bottom"
      Tapped="Grid_OnTapped"
      Tag="{Binding}"></Grid>

then inside event Grid_OnTapped, I can use the Tag property of Grid to know which item is tapped.

But when change to x:Bind, it's no longer work. Exception throwed: "Object reference is not set to an instance of an object"

Further test, this code will display the name of the class

<TextBlock Text="{x:Bind}/>

But that the only thing work

Please help. Thanks

1
  • Could you show the code of your constructor? Commented Oct 23, 2015 at 9:10

1 Answer 1

1

{x:Bind} is for binding to properties in the code-behind of the view. It has a performance advantage over {Binding} because normal binding uses reflection to find properties, whereas x:Bind does not. x:Bind will bind to strongly typed properties in the code-behind.

Generally, you would use x:Bind to gain performance in XAML.

In your case, it would be a better idea to bind the to DataContext instead, in your case, is just {Binding}. Which is what you have already done previously.

Perhaps you have misunderstood the usage of x:Bind? Here's an article explaining how it should be used.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. I misunderstood of x:Bind. Thought it was {Binding} replacement. Turn out this is a whole new mechanism.
Arguably, the far more important improvement of {x:Bind} over {Binding} is the maintainability aspect. It performs compile-time validation, catching bugs as early as possible. Also worth noting: {x:Bind} can be used with functions just as well. It is not exclusively for properties (see {x:Bind} markup extension).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.