4

I have recently upgraded my OS to Windows 10 from Windows 8.1. I'm using VS 2013 With update 4. My app using the Treeview control from XAMLToolkit, and it works perfectly on Windows 8.1 environment. But under Windows 10, it gives me the following error. Please help.

This is the XAMLToolkit version I've used: nuget.org/packages/winrtxamltoolkit.windows

Exception message:

System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component. at Windows.UI.Xaml.Controls.ItemsControl.get_ItemTemplate() at WinRTXamlToolkit.Controls.HeaderedItemsControl.PrepareHeaderedItemsControlContainer(HeaderedItemsControl control, Object item, ItemsControl parentItemsControl, Style parentItemContainerStyle) at WinRTXamlToolkit.Controls.HeaderedItemsControl.PrepareHeaderedItemsControlContainerForItemOverride(DependencyObject element, O

Stacktrace:

at Windows.UI.Xaml.Controls.ItemsControl.get_ItemTemplate() at WinRTXamlToolkit.Controls.HeaderedItemsControl.PrepareHeaderedItemsControlContainer(HeaderedItemsControl control, Object item, ItemsControl parentItemsControl, Style parentItemContainerStyle) at WinRTXamlToolkit.Controls.HeaderedItemsControl.PrepareHeaderedItemsControlContainerForItemOverride(DependencyObject element, Object item, ItemsControl parent, Style parentItemContainerStyle) at WinRTXamlToolkit.Controls.TreeView.PrepareContainerForItemOverride(DependencyObject element, Object item) at Windows.UI.Xaml.FrameworkElement.MeasureOverride(Size availableSize)

Inner exception is null

mpx
  • 3,081
  • 2
  • 26
  • 56
SurenSaluka
  • 1,534
  • 3
  • 18
  • 36

2 Answers2

1

I encountered same issue, what i did is just removed the itemtemplate inside treeview control and added separately in page resource and i refered the itemtemplate to my treeview control. it solved my issue.

<Page.Resources>

<DataTemplate x:Name="TreeViewItemTemplate">
<Grid>
<TextBlock Text="{Binding Name}" />
</Grid>

<XCDATA:DataTemplateExtensions.Hierarchy>
<XCDATA:HierarchicalDataTemplate ItemsSource="{Binding Items}" />
</XCDATA:DataTemplateExtensions.Hierarchy>

</DataTemplate>

</Page.Resources>

<XC:TreeView 
    ItemTemplate="{StaticResource TreeViewItemTemplate}"
    ItemsSource="{Binding ObjShopItems}">      
</XC:TreeView>
Antti29
  • 2,953
  • 12
  • 34
  • 36
Nambukarthy
  • 96
  • 11
0

Seems that you are using a HierarchicalDataTemplate in your XAML code for the TreeView. Replacing the XAML with the corresponding C# code will help. We can set the DataTemplateExtensions.Hierarchy attached property in code-behind in Loaded event for the TreeView, like this:

<controls:TreeView x:Name="treeView"
                   Loaded="treeView_Loaded"
...

And in code-behind:

private void treeView_Loaded(object sender, RoutedEventArgs e)
        {
            //don't know why, but in Windows 10 if this code is as XAML, the app falls with a ComExcpetion
            //so the corresponding XAML should be commented out like this:
            //...
            //<controls:TreeView.ItemTemplate>
            //  <DataTemplate>
            //   <!-- <data:DataTemplateExtensions.Hierarchy>
            //    <data:HierarchicalDataTemplate ItemsSource="{Binding Folders}" />
            //   </data:DataTemplateExtensions.Hierarchy> -->
            //  <Grid>
            //...
            WinRTXamlToolkit.Controls.Data.DataTemplateExtensions.SetHierarchy(treeView.ItemTemplate, new WinRTXamlToolkit.Controls.Data.HierarchicalDataTemplate
                {
                    ItemsSource = new Windows.UI.Xaml.Data.Binding { Path = new PropertyPath("Folders") }
                });
        }
Artemious
  • 1,980
  • 1
  • 20
  • 31
  • Please explain the line "ItemsSource = new Windows.UI.Xaml.Data.Binding { Path = new PropertyPath("Folders") }" What is "Folders"? is this the hierarchy I need to provide? I'm using MVVM to bind data and is there another way of doing this? – SurenSaluka Aug 03 '15 at 06:57
  • 1
    I was talking about `HierarchicalDataTemplate`. So my answer is useful for you only in case if you were using this thing. Only if you had in your XAML something like this: ` ....` You can see here this line: ItemsSource="{Binding Folders}" So "Folders" is a subitems path. A list of children. – Artemious Aug 03 '15 at 12:18
  • Hi, yes I do use HierarchicalDataTemplate on my XAML, and vendors of XAMLToolkit says they will work on it and release a new version. So I think I will wait till they get back. https://winrtxamltoolkit.codeplex.com/discussions/642218 – SurenSaluka Aug 04 '15 at 08:53
  • Until they fix it, please, mark this as an answer, if you find it working fine. (At least, I solved it this way and it works great). – Artemious Aug 05 '15 at 16:11