Hi
can any one tell me what is difference b/w DataContext property and itemsorce, source and where these use...........?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Priya LingePosted Nov 21, 2011, 2:45 AM
1.DataContext property is exposed by FrameworkElement base class.
2.ItemsSource is defined by the ItemsControl class.
3.DataContext is of type Object.
4.ItemsSource property is of type IEnumerable.
5.DataContext is used to hold common data for other controls to bind.
we set the DataContext in a top-level parent element.
By doing this, many other child element can bind the appropriate value from
the data that top-level element holds.
DataContext does nothing for generating template.
6.ItemsSource property is use to generate template
Example >
7.DataContext is mainly used to hold common data that other child want to share.
Thus it can be inherited by other child elements without problem.
8.ItemsSource is not used to share data in the visual tree. It only valid for the element that defined.
9.Suppose ,we have several child elements that will share a common data source, we can set DataContext property for the parent elements.
10.we use ItemsSource for ItemsSource in most cased to generate template.
Example >
Hope this will help you.Thanks.
Satyapriya NayakPosted Nov 18, 2011, 11:03 AM
Please refer the below links.
http://www.c-sharpcorner.com/uploadfile/tirthacs/difference-between-datacontext-and-itemssource-in-wpfsilverlight/
http://jimzhou1985.blogspot.com/2009/05/what-is-difference-between-datacontext.html
Thanks
Datta KharadPosted Nov 18, 2011, 8:16 AM
You can refer this link...
http://stackoverflow.com/questions/3169245/difference-between-itemssource-and-datacontext-as-pertains-to-listbox
http://www.sourcecode.mncinterview.com/2011/08/difference-between-datacontext-and.html