CompositeCollection support?

Topics: Conventions, Extensibility, Feature Requests
May 7, 2012 at 1:17 PM
Edited May 7, 2012 at 1:17 PM

Is there any form of support for CompositeCollection. Basically, it's used for an ItemsControl.ItemsSource when you want to bind to 2 or more collections. Apparently I can't bind to a property and the CC has no datacontext. The below code shows it not-working :P

    <ItemsControl>
        <ItemsControl.ItemsSource>
            <Binding>
                <Binding.Source>
                    <CompositeCollection>
                        <CollectionContainer Collection="{Binding Path=Nodes}" />
                        <CollectionContainer Collection="{Binding Path=Connections}" />
                    </CompositeCollection>
                </Binding.Source>
            </Binding>
        </ItemsControl.ItemsSource>
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <local:NodePanel />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>

May 7, 2012 at 1:47 PM
Edited May 7, 2012 at 1:48 PM

Solution was to follow this:

http://stackoverflow.com/questions/6446699/how-do-you-bind-a-collectioncontainer-to-a-collection-in-a-view-model

1) Made the CompositeCollection a resource in the UserControl.

2) Gave my UserControl the name "root" (it doesnt matter what it is), set each CollectionContainer's binding source to x:Reference root

The view/datatemplate for the items was not set correctly using this method.