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 - Bound HeaderedItemsControls inherit ItemContainerStyle differently from unbound controls?

 
 
Old 01-10-2006   #1 (permalink)
Ryan Milligan


 
 

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



My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Fully editable unbound grid .NET General
Where is the data bound combo box like in vb6? .NET General
Are licenses language-bound? Vista installation & setup


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