Question

I've got an ObservableCollection of POCOs (Plain old CLR Objects) that I want to represent in a tabbed idiom. Prefereably using the MVVM pattern, is there a way to bind the collection of TabItems to the count of my POCO collection?

So, in this case if there are 3 items in my collection, I'd like to see 3 TabItems. Each TabItem would contain the same controls in the same location, each control bound to properties of the appropriate object in the collection.

I'm just looking for an overview of the approach I might use or a link to an example. If you need more info, feel free to ask.

Thanks.

Was it helpful?

Solution

I'd probably create an ObservableColletion with your POCO items in it. You could then bind that ObservableCollection to any of the Silverlight Item Rendering controls. You'll have to modify the default rendering template to create your tabs...but using that method, your tabs will constantly be up to date with the items in the collection without having to put any code in the code behind file.

UPDATE

Here's a link to the Silverlight Forums where somebody built a TabControl using the ItemsControl with sample XAML code:

http://silverlight.net/forums/t/12271.aspx

...just scroll down a bit to see the sample.

OTHER TIPS

One way to do this is to use a value converter (IValueConverter) to return your POCO wrapped in a TabItem. I posted an example here as part of a related question. There is also sample xaml binding and injection of the ViewModel as a parameter to the value converter.

/jhd

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top