Skip to main content
  1. About
  2. For Teams
Asked
Viewed 912 times
0

I was reading some code and came across this;

<TabControl ItemSource="{Binding}"
    ItemTemplate="{StaticResource TabItemTemplate}" />

I have a pretty good handle on {Binding Path=Something} but I can't find a sastisfactory nswer to ItemSource="{Binding}" all by itself. The nearest I got to an answer was

"This simply returns the current data context (more about that later)." BTW, there was nothing more.

So I wonder if anyone would like to expand on this and leave out all the "One Way, Two Way, Element... binding. Just the part about {Binding}.

Thank you.

2 Answers 2

3

When you specify a path in a binding, it's relative to the DataContext; if the path is empty, then it refers to the DataContext itself. So the binding will just return the current DataContext as its value.

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

4 Comments

Would that not be the default if it was just left out?
@ScottinTexas, if what was left out?
Sorry, typed while just thinking. If the {Binding} was left out, wouldn't the ItemsSource inherit the DataContext of the parent?
@ScottinTexas, the TabControl would still inherit the DataContext, but the ItemsSource would be null. It wouldn't make sense for all properties to get the value of the DataContext...
0

ItemsSource="{Binding}" means binding the datacontext of the TabControl to the ItemsSource.

ItemsSource="{Binding Path=Something}", means binding the (DataContext of the TabControl).Something to the ItemsSource.

Comments

Your Answer

Post as a guest

Required, but never shown

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.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.