![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | 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? |
| | #2 (permalink) |
| Guest | 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. |
| | #3 (permalink) |
| Guest | 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. |
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Binding inside binding question | Yoavo | Avalon | 0 | 12-03-2007 08:24 AM |
| Binding to a Foreign Key Binding? | -=B3N=- | Avalon | 0 | 06-14-2007 06:45 AM |
| Binding Question (Binding in General) | Jason | Avalon | 2 | 05-09-2007 04:41 AM |
| How to suspend binding | Patrice Ongla | Avalon | 1 | 10-25-2006 07:25 PM |
| Two-Way Xml Binding? | Nick Howell | Avalon | 0 | 03-05-2006 07:11 PM |