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

Bound HeaderedItemsControls inherit ItemContainerStyle differently from unbound controls?

Closed Thread
 
Thread Tools Display Modes
Old 01-10-2006   #1 (permalink)
Ryan Milligan
Guest


 

Bound HeaderedItemsControls inherit ItemContainerStyle differently from unbound controls?

Has anyone tried to use nested ItemContainerStyles in bound scenarios using
TreeViewItems or MenuItems? Consider the following XAML:

<Window x:Class="WindowsApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/avalon/2005"
xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"
Title="WindowsApplication1"
>

<Window.Resources>
<XmlDataProvider x:Key="Data" XPath="Items">
<Items xmlns="">
<Child text="Child">
<Grandchild text="Grandchild">
<Grandchild text="Shouldn't see this" />
</Grandchild>
</Child>
</Items>
</XmlDataProvider>
<Style x:Key="ChildTemplate" TargetType="{x:Type HeaderedItemsControl}">
<Setter Property="Background" Value="Green" />
<Setter Property="ItemContainerStyle" Value="{StaticResource
GrandchildTemplate}" />
</Style>
<Style x:Key="BoundChildTemplate" TargetType="{x:Type
HeaderedItemsControl}" BasedOn="{StaticResource ChildTemplate}">
<Setter Property="Header" Value="{Binding XPath=@text}" />
<Setter Property="ItemsSource" Value="{Binding XPath=Grandchild}" />
</Style>
<Style x:Key="GrandchildTemplate" TargetType="{x:Type
HeaderedItemsControl}">
<Setter Property="Background" Value="Orange" />
</Style>
</Window.Resources>
<DockPanel>
<TreeView DockPanel.Dock="Top">
<TreeViewItem
Header="Bound"
ItemsSource="{Binding Source={StaticResource Data}, XPath=Child}"
ItemContainerStyle="{StaticResource BoundChildTemplate}" />
<TreeViewItem Header="Unbound" ItemContainerStyle="{StaticResource
ChildTemplate}">
<TreeViewItem Header="Child">
<TreeViewItem Header="Grandchild" />
</TreeViewItem>
</TreeViewItem>
</TreeView>
</DockPanel>
</Window>


The basic scenario here is a TreeView with two TreeViewItems in the root
(same behaviour happens if you replace "TreeView" with "Menu"), one of which
is bound to a datasource, and one of which has its items specified manually.
Both root items have an ItemContainerStyle set -- the bound item's container
style is based on the unbound one, but adds some recursive binding goop. The
end result of this mark-up should be that both the bound and unbound items
look exactly the same: they should both contain a green child that says
"Child", which contains an orange child that says "Grandchild". The unbound
item behaves as expected, but the bound one does not.

All of the bound item's descendents apparently get the same
ItemContainerStyle, and I can't seem to find a way to override it in the
middle. It contains three nested, green children, the third of which is the
"Shouldn't see this" element in the XML, which shouldn't be displayed
because the grandchild ItemContainerStyle doesn't have any binding
information. Am I missing something? Is this a bug? This is in the November
'05 CTP. Thanks in advance!

-- Ryan Milligan


Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Where is the data bound combo box like in vb6? bill .NET General 2 07-22-2008 09:35 PM
How reflect the changes in array to bound grid Latha .NET General 1 03-19-2008 12:54 PM
inherit controls in WPF Yoavo Avalon 1 10-09-2007 10:59 AM
Are licenses language-bound? Rain in Spain Vista installation & setup 8 02-06-2007 10:05 AM








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