Howto Bind to Object created at Runtime?

Oct 15, 2009 at 7:45 PM

Hey there,

first let me thank you for releasing this wonderful project. I am thrilled to
integrate Thriple into my upcoming projects.

I am programming within .net for a couple of years, but I'm quite new to XAML

and the whole WPF thing in general. So I hope someone here can help me.

There are a ton of HowTos describing how to bind a static XML File or precreated Object
via XmlDataProvider and ObjectDataProvider, but I couldn't find how to do the following:

I have a series of objects of the same type which are loaded bit by bit from a webservice when
my app is running. So I want to dynamically add new objects at runtime and show them pretty much
like the Blogroll Example does. Anyone know how I can achieve this?




Oct 15, 2009 at 7:47 PM

Set an ItemsControl's ItemsSource to an ObservableCollection<T> and then add the objects to that collection.  The ItemsControl will automatically add those items to its list on screen.

Oct 15, 2009 at 8:26 PM

Well, I am currently using a lot of Blogroll3Ds XAML code, therefore I have a ListBox element.

When the application starts I set listbox1.ItemsSource = oList;

oList is (as suggested by you) ObservableCollection<MyObject>

But it doesn't seem to work yet, as objects are already added to the Collection but nothing appears on screen :(
Is it relevant that the ObservableCollection gets updated via an event?




Oct 15, 2009 at 9:38 PM

Ok, don't mind. I should have looked at my Z-index ;)