Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - CompositeCollections/ CollectionContainer binding issue

 
 
Old 01-10-2006   #1 (permalink)
RyanLeeSchneider


 
 

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 dataata}">
<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 dataata}">
<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 SpecsSystem Spec
Old 01-10-2006   #2 (permalink)
auto239436@hushmail.com


 
 

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 SpecsSystem Spec
Old 01-10-2006   #3 (permalink)
RyanLeeSchneider


 
 

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 SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Binding to DL VB Script


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46