Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So basically I have an ItemsControl that is bound to a collection of UI elements and displays that collection in a canvas. I was wondering if it's possible to bind the ItemsSource of an ItemsControl to more than one source? Because I have another collection of UI elements that I want to display in that same canvas but I don't know how to do that. If it's not possible can anyone suggest a workaround? Thanks!
Posted

Create a new collection that copies the items from both the others and bind to that?
 
Share this answer
 
Comments
industryunleash 19-Jul-10 17:16pm    
That would probably work except that each collection is displayed in the UI using different templates, so this bigger collection would have to be able to tell the UI which template to use when.
The DataContext can be set anywhere up the visual tree, so you can set it directly at the point that needs to be used. This means that you don't need to worry about this, because your second UI elements can bind to a different DataContext instead.
 
Share this answer
 
Hello,

I think this is the example you are looking for :
XML
<ListBox Name="listbox" DisplayMemberPath="Test">
       <ListBox.ItemsSource>
           <CompositeCollection>
               <CollectionContainer Collection="{Binding Source={StaticResource myDataSource2}, Path=One}"/>
               <CollectionContainer Collection="{Binding Source={StaticResource myDataSource}, Path=Two}"/>
               <CollectionContainer Collection="{Binding Source={StaticResource myDataSource}, Path=Three}"/>
           </CompositeCollection>
       </ListBox.ItemsSource>
   </ListBox>



Hope this help you !
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900