WPF: Example of ItemsControl bound to an ObservableCollection

One of the most exciting feature I learned about in the WPF course two weeks ago was that you can bind an ObservableCollection's content to just any type of Panel, by using an ItemsControl and the ItemsPanelTemplate property.
In order to check if I had understood the technique properly, I made a small working example. It actually worked out pretty well, so well in fact that I decided to publish it, hoping that it can help someone out there.
I am walking you through that example here. I published it as an XBAP (open in IE, with .NET 3.0 installed). Also, the source files can be found here: XAML, code behind, dependency object. Finally, the whole project can be downloaded here.
ItemsControl example with ObservableCollection
Print | posted on Thursday, April 12, 2007 11:42 PM

Feedback

# re: WPF: Example of ItemsControl bound to an ObservableCollection

left by Hermann Rösch at 3/19/2008 10:33 PM Gravatar
Great sample! Can you share the Silverlight source code? I don't understand how you deal with the UIPropertyMetadata for the XBAP.

# re: WPF: Example of ItemsControl bound to an ObservableCollection

left by Laurent at 3/20/2008 11:18 PM Gravatar
Hi,

This example is an XBAP, not Silverlight (when it was written, Silverlight with .NET was not available yet). The source code is available.

I don't quite understand your question. Do you wish to see the same example written in Silverlight? What about the meta data? The syntax to declare a DependencyProperty is different in Silverlight. That said, DataBinding in Silverlight using DependencyProperties is not quite ripe yet, so for the moment you should use INotifyPropertyChanged instead.

HTH,
Laurent

# re: WPF: Example of ItemsControl bound to an ObservableCollection

left by Ray Metz at 11/20/2008 8:19 AM Gravatar
Thanks. I plan to use this to dynamically add items to a pawnshop loan.

# re: WPF: Example of ItemsControl bound to an ObservableCollection

left by TheNullPointer at 8/25/2009 4:02 AM Gravatar
hi,
this is a nice example for the items control.
in the xaml file you wrote that you didn't add the scrollview to avoid making the file unnecessarily complex.
I would like to use a similar concept in my application but I need a scrollview. I'm rather new to wpf, I'm afraid I didn't get it to work. No matter where I added a scrollview, it either showed up in the wrong place or there were compiler exceptions (scrollpanel not allowed here).
Can you please give me a hint? thx

# re: WPF: Example of ItemsControl bound to an ObservableCollection

left by Dan at 4/15/2010 12:15 PM Gravatar
I am using the MVVM. I wanted to try using my main display with something like this. But I keep running into the same issue. It displays "Collection" and not the view.

So basically. I have a class that when loading should load the datatemplate assigned for that class.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: