![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | CompositeCollections/ CollectionContainer binding issue I'm trying to populate a listbox from an object like this: class Data { public string Item1; public List<ItemData> AdditionalItems; } class ItemData { override public string ToString() { return "Test";} } I have a content control that has it's datacontext set to an instance of Data by another event: <DockPanel> <DockPanel.Resources> .... (See below) </DockPanel.Resources> <ContentControl Name="Details" Content="{Binding }"/> </DockPanel> The ... is my DockPanel.Resources, if I use this it works: <DataTemplate DataType="{x:Type data ata}"><StackPanel> <TextBlock Text="{Binding Path=Item1}"/> <ListBox ItemsSource={Binding Path=AdditionalItems}"/> </StackPanel> </DataTemplate> However, I want the TextBlock to actually be the first item in the list instead of a separate element, so I tried: <DataTemplate DataType ="{x:Type data ata}"><ListBox> <ListBox.ItemsSource> <CompositeCollection> <ListBoxItem> <TextBlock Text={Binding Path=Item1}/> </ListBoxItem> <!--Problem Child below--> <CollectionContainer Collection={Binding Path=AdditionalItems}/> </CompositeCollection> </ListBox.ItemsSource> However, in this case I only get Item1 in the list. If I use the "GreekHeroes" xml from the CompositeCollections SDK sample, it works fine (after copying over the XmlDataSource, obviously): <CollectionContainer Collection="{Binding Source={StaticResource GreekHeroesData}}" /> The problem is I don't have a StaticResource to bind to, other things I've tried are: <CollectionContainer Collection="{Binding Source={Binding Path=AdditionalItems}}" /> and <CollectionContainer Collection="{Binding RelativeSource=/ParentData, Path=AdditonalItems}" /> All with no success to date. I looked into using a DynamicResource, but couldn't figure out how. Any suggestions? |
My System Specs![]() |
| | #2 (permalink) |
| | Re: CompositeCollections/ CollectionContainer binding issue Heh, classic Avalon crap- they use a sample with a StaticResource that makes it look simple, but doesn't work with bindings. I'm really pissed at whoever makes these samples, they make it look easy but hide the fact that it breaks for anything useful. The problem you're running into is that CompositeCollection is not a Freezable. In order to bind to the data context (where AdditionalItems comes from) you need to have a chain of Freezables to your data context. Also note, that Binding to ElementNames will not be resolved as they use the same path. Options- Create your own Freezable CompositeCollection, or create a collection that combines the two in your code. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: CompositeCollections/ CollectionContainer binding issue Thanks for the advice, I'll look into Freezable and what that entails, in the meantime I guess I'll just have 2 different treeviews, or do what I was doing (make each of the 2 child TreeViewItems their own treeview control, though the issue with this is I have to write custom selection bubbling code, and I'm sure I'll run into other issues down the road. "auto239436@hushmail.com" wrote: > Options- Create your own Freezable CompositeCollection, or create a > collection that combines the two in your code. |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Binding to DL | VB Script | |||