views:

626

answers:

2

I have a wpf user control which exposes an IEnumerable ItemsSource DependencyProperty. I bind this property to a ListBox control in my UserControl.

I would like to know how I can make my user control work when a CompositeCollection is given. Currently I'm utilising my control like this:

<my:uc>
  <my:uc.ItemsSource>
    <CompositeCollection>
      <CollectionContainer Collection="{My Binding}"></CollectionContainer>
      <CollectionContainer Collection="{My Binding}"></CollectionContainer>
    </CompositeCollection>
  </my:uc.ItemsSource>
</my:uc>

I would like this to display the contents of these CollectionContainers in the list box, but at the moment its not enumerating through the containers. The only items my listbox shows is two "System.Data.CollectionContainer" items.

[b]Edit:[/b] The XAML designer informs me that "Property 'ItemsSource' does not support values of type 'CompositeCollection'." I think this is my problem.. but how do I make it "support" CompositeCollection?

A: 

I think that what you are getting is the ToString method of your object, which by default returns the name of the type.

Try overriding ToString and returning the value you want to see in your list.

Shiraz Bhaiji
The problem is that the CollectionContainer shouldn't render itself at all, instead it needs to supply its child elements.
vanja.
A: 

The correct answer was to create a class that extends ItemsControl. You can not use any XAML when designing the control, but it does give you the special ItemsSource property which supports CollectionContainers. The view of the control should be defined in its ContentTemplate property.

vanja.