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
245 views
in Technique[技术] by (71.8m points)

.net - What does 'ItemsSource="{Binding}"' mean?

I'm attempting to learn WPF by unravelling a frankly nightmarish project written by the guy who was in this job before me. Sorry if some of my questions are pretty much homework-level but I'm trying to work out what existing XAML does, with an insufficient understanding of the concepts behind it...

Anyway, I have a ListView with this as part of its definition:

<ListView 
    DataContext="{StaticResource XMLFileGroups}"
    ItemContainerStyle="{StaticResource XMLItemStyle}"
    ItemsSource="{Binding}">

Now, I can kind of get my head around what the "DataContext" and "ItemContainerStyle" lines are doing; they appear to be referencing a method of sorting an existing list, and a structure defining some visual behaviour of the ListView, respectively.

What's wrecking me is the fact that the ItemsSource is listed as "{Binding}". All that says to me is that there is some kind of databinding in place, but I don't understand how the line can possibly be meaningful and yet removing it stops any data from being displayed.

Can someone shed some light on what is happening here, or where I should look for the actual binding definition? I just don't understand what I'm seeing, here.

question from:https://stackoverflow.com/questions/3874218/what-does-itemssource-binding-mean

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

1 Answer

0 votes
by (71.8m points)

Without a path, {Binding} will bind to the DataContext itself.
Adding a path will bind to a property of the datacontext.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
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

...