Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts 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

Problem when generating Tab items via binding to groups.

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 07-08-2006   #1 (permalink)
=?Utf-8?B?Sm9zaCBTbWl0aA==?=
Guest


 

Problem when generating Tab items via binding to groups.

I think that I may have stumbled across a bug, but it's possible that I'm
doing something wrong. I set the ItemsSource of a TabControl to the Groups
property of a CollectionViewSource. When I select a tab item, an exception
is thrown stating that an invalid cast occurred when casting a TabItem to a
GroupItem. I checked this out in Reflector and noticed that the
ItemContainerGenerator.GetRealizedItemBlockCount method is using a C-style
cast, making the assumption that
ItemContainerGenerator.RealizedItemBlock.ContainerAt(int) is going to return
a GroupItem. I don't see why this assumption should be made. Is there some
overriding reason for not allowing TabItems to be the container?

Here's the test app (there is no code-behind):

<Window x:Class="TabbedGroups.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="TabbedGroups" Height="300" Width="300"
>

<Window.Resources>
<XmlDataProvider x:Key="cities">
<x:XData>
<Cities xmlns="">
<City CityName="Shanghai" Country="People's Republic of China"
Continent="Asia"/>
<City CityName="Tokyo" Country="Japan"
Continent="Asia"/>
<City CityName="Sydney" Country="Australia"
Continent="Australia"/>
<City CityName="Munich" Country="Germany"
Continent="Europe" />
<City CityName="Stockholm" Country="Sweden"
Continent="Europe" />
<City CityName="Chicago" Country="United States"
Continent="North America" />
<City CityName="Denver" Country="United States"
Continent="North America"/>
<City CityName="Los Angeles" Country="United States"
Continent="North America"/>
<City CityName="Buenos Aires" Country="Argentina"
Continent="South America" />
</Cities>
</x:XData>
</XmlDataProvider>

<CollectionViewSource x:Key="citiesView" Source="{Binding
Source={StaticResource cities}, XPath=Cities/City}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="@Country" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>

<DataTemplate x:Key="cityListItemTemplate">
<TextBlock Text="{Binding XPath=@CityName}" Margin="2,4"/>
</DataTemplate>

<DataTemplate x:Key="cityListTemplate">
<!-- NOTE: This ListBox can be removed and the exception is still thrown. -->
<ListBox
DataContext="{Binding Path=Items}"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding}"
ItemTemplate="{StaticResource cityListItemTemplate}"/>
</DataTemplate>

</Window.Resources>

<Grid DataContext="{StaticResource citiesView}">

<TabControl
x:Name="tabControl"
ContentTemplate="{StaticResource cityListTemplate}"
ItemsSource="{Binding Path=Groups}" />

</Grid>
</Window>
*****************************************
Here is part of the exception that is thrown when clicking on a tab header:

{System.InvalidCastException: Unable to cast object of type
'System.Windows.Controls.TabItem' to type 'System.Windows.Controls.GroupItem'.
at
System.Windows.Controls.ItemContainerGenerator.GetRealizedItemBlockCount(RealizedItemBlock rib, Int32 end)
at
System.Windows.Controls.ItemContainerGenerator.DoLinearSearch(DependencyObject& container, Object& item, Int32& itemIndex)
at
System.Windows.Controls.ItemContainerGenerator.ContainerFromItem(Object item)
at System.Windows.Controls.Primitives.Selector.ItemSetIsSelected(Object
item, Boolean value)
at
System.Windows.Controls.Primitives.Selector.SelectionChanger.CreateDeltaSelectionChange(List`1 unselectedItems, List`1 selectedItems)
at System.Windows.Controls.Primitives.Selector.SelectionChanger.End()
at System.Windows.Controls.Primitives.Selector.SetSelectedHelper(Object
item, FrameworkElement UI, Boolean selected)
at
System.Windows.Controls.Primitives.Selector.NotifyIsSelectedChanged(FrameworkElement container, Boolean selected, RoutedEventArgs e)
at System.Windows.Controls.Primitives.Selector.OnSelected(Object sender,
RoutedEventArgs e)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target,
RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source,
RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.Controls.TabItem.OnSelected(RoutedEventArgs e)
at System.Windows.Controls.TabItem.OnIsSelectedChanged(DependencyObject
d, DependencyPropertyChangedEventArgs e) ...

*****************************************
Any help or suggestions about this issue would be much appreciated.

Thank you,
Josh Smith

My System SpecsSystem Spec
Old 07-08-2006   #2 (permalink)
=?Utf-8?B?Sm9zaCBTbWl0aA==?=
Guest


 

RE: Problem when generating Tab items via binding to groups.

I've been playing around with this more, and found another manifestation of
the same problem. I bound a TreeView's ItemsSource to a
ListCollectionView's Groups property, and set the ItemTemplate to this
template:

<HierarchicalDataTemplate x:Key="hierarchicalItemTemplate"
ItemsSource="{Binding Path=Items}">
<TextBlock Text="{Binding Converter={StaticResource converter}}"
Margin="4,2" />
</HierarchicalDataTemplate>

When navigating the tree items with the Up and Down arrow keys, the same
exception is thrown as listed in my previous post.

If you need my complete source code to test this, please let me know and I'd
be happy to post it.

Thanks,
Josh

"Josh Smith" wrote:

> I think that I may have stumbled across a bug, but it's possible that I'm
> doing something wrong. I set the ItemsSource of a TabControl to the Groups
> property of a CollectionViewSource. When I select a tab item, an exception
> is thrown stating that an invalid cast occurred when casting a TabItem to a
> GroupItem. I checked this out in Reflector and noticed that the
> ItemContainerGenerator.GetRealizedItemBlockCount method is using a C-style
> cast, making the assumption that
> ItemContainerGenerator.RealizedItemBlock.ContainerAt(int) is going to return
> a GroupItem. I don't see why this assumption should be made. Is there some
> overriding reason for not allowing TabItems to be the container?
>
> Here's the test app (there is no code-behind):
>
> <Window x:Class="TabbedGroups.Window1"
> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
> Title="TabbedGroups" Height="300" Width="300"
> >

> <Window.Resources>
> <XmlDataProvider x:Key="cities">
> <x:XData>
> <Cities xmlns="">
> <City CityName="Shanghai" Country="People's Republic of China"
> Continent="Asia"/>
> <City CityName="Tokyo" Country="Japan"
> Continent="Asia"/>
> <City CityName="Sydney" Country="Australia"
> Continent="Australia"/>
> <City CityName="Munich" Country="Germany"
> Continent="Europe" />
> <City CityName="Stockholm" Country="Sweden"
> Continent="Europe" />
> <City CityName="Chicago" Country="United States"
> Continent="North America" />
> <City CityName="Denver" Country="United States"
> Continent="North America"/>
> <City CityName="Los Angeles" Country="United States"
> Continent="North America"/>
> <City CityName="Buenos Aires" Country="Argentina"
> Continent="South America" />
> </Cities>
> </x:XData>
> </XmlDataProvider>
>
> <CollectionViewSource x:Key="citiesView" Source="{Binding
> Source={StaticResource cities}, XPath=Cities/City}">
> <CollectionViewSource.GroupDescriptions>
> <PropertyGroupDescription PropertyName="@Country" />
> </CollectionViewSource.GroupDescriptions>
> </CollectionViewSource>
>
> <DataTemplate x:Key="cityListItemTemplate">
> <TextBlock Text="{Binding XPath=@CityName}" Margin="2,4"/>
> </DataTemplate>
>
> <DataTemplate x:Key="cityListTemplate">
> <!-- NOTE: This ListBox can be removed and the exception is still thrown. -->
> <ListBox
> DataContext="{Binding Path=Items}"
> IsSynchronizedWithCurrentItem="True"
> ItemsSource="{Binding}"
> ItemTemplate="{StaticResource cityListItemTemplate}"/>
> </DataTemplate>
>
> </Window.Resources>
>
> <Grid DataContext="{StaticResource citiesView}">
>
> <TabControl
> x:Name="tabControl"
> ContentTemplate="{StaticResource cityListTemplate}"
> ItemsSource="{Binding Path=Groups}" />
>
> </Grid>
> </Window>
> *****************************************
> Here is part of the exception that is thrown when clicking on a tab header:
>
> {System.InvalidCastException: Unable to cast object of type
> 'System.Windows.Controls.TabItem' to type 'System.Windows.Controls.GroupItem'.
> at
> System.Windows.Controls.ItemContainerGenerator.GetRealizedItemBlockCount(RealizedItemBlock rib, Int32 end)
> at
> System.Windows.Controls.ItemContainerGenerator.DoLinearSearch(DependencyObject& container, Object& item, Int32& itemIndex)
> at
> System.Windows.Controls.ItemContainerGenerator.ContainerFromItem(Object item)
> at System.Windows.Controls.Primitives.Selector.ItemSetIsSelected(Object
> item, Boolean value)
> at
> System.Windows.Controls.Primitives.Selector.SelectionChanger.CreateDeltaSelectionChange(List`1 unselectedItems, List`1 selectedItems)
> at System.Windows.Controls.Primitives.Selector.SelectionChanger.End()
> at System.Windows.Controls.Primitives.Selector.SetSelectedHelper(Object
> item, FrameworkElement UI, Boolean selected)
> at
> System.Windows.Controls.Primitives.Selector.NotifyIsSelectedChanged(FrameworkElement container, Boolean selected, RoutedEventArgs e)
> at System.Windows.Controls.Primitives.Selector.OnSelected(Object sender,
> RoutedEventArgs e)
> at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target,
> RoutedEventArgs routedEventArgs)
> at System.Windows.EventRoute.InvokeHandlersImpl(Object source,
> RoutedEventArgs args, Boolean reRaised)
> at System.Windows.UIElement.RaiseEventImpl(RoutedEventArgs args)
> at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
> at System.Windows.Controls.TabItem.OnSelected(RoutedEventArgs e)
> at System.Windows.Controls.TabItem.OnIsSelectedChanged(DependencyObject
> d, DependencyPropertyChangedEventArgs e) ...
>
> *****************************************
> Any help or suggestions about this issue would be much appreciated.
>
> Thank you,
> Josh Smith

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Thumbnail problem. Computer not generating them or something. Flash 103 Vista music pictures video 5 07-26-2008 10:00 AM
Binding an ImageBrush Problem star-italia .NET General 5 06-13-2008 02:36 AM
PROBLEM WITH VS 2008 WINFORMS LINQ TREATED FOR GENERATING A INSTALLER VictorLeo .NET General 1 03-29-2008 05:26 PM
SQLMetal - Problem generating VB from DBML Adrian .NET General 6 03-28-2008 04:40 AM
Moving Start Groups lose your items Robert Paresi Vista security 1 05-21-2007 03:42 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 51