Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

CompositeCollections/ CollectionContainer binding issue

Closed Thread
 
Thread Tools Display Modes
Old 01-10-2006   #1 (permalink)
RyanLeeSchneider
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 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?


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

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


Closed Thread

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








Vistax64.com 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 2005-2008

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 47 48 49 50