This is a migrated thread and some comments may be shown as answers.

Catastrophic failure in setting the itemtemplate using code behind for Treeview

1 Answer 86 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Kartheek
Top achievements
Rank 1
Kartheek asked on 23 Feb 2011, 02:14 AM
Hi,

I am getting Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)) when trying to set the value for itemTemplate.

my code:
Telerik.Windows.Controls.HierarchicalDataTemplate template = (Telerik.Windows.Controls.HierarchicalDataTemplate)this.Resources["ProductTemplate"];
Telerik.Windows.Controls.HierarchicalDataTemplate template1 = (Telerik.Windows.Controls.HierarchicalDataTemplate)this.Resources["TreeTemplateLevel"];
template.ItemTemplate.SetValue(Telerik.Windows.Controls.RadTreeView.ItemTemplateProperty, template1);

XAML:
<telerik:HierarchicalDataTemplate x:Key="TreeTemplateLevel" 
ItemsSource="{Binding Path=ChildItems}">
<StackPanel Orientation="Horizontal">
<HyperlinkButton Content="{Binding Title}" NavigateUri="{Binding Path=NavigateUri}" TargetName="_blank" VerticalAlignment="Center" />
<Button Content="info"/>
</StackPanel>
</telerik:HierarchicalDataTemplate>
        <telerik:HierarchicalDataTemplate x:Key="ProductTemplate" ItemsSource="{Binding Path=ChildSPLists}" ItemTemplate="{StaticResource ProductTemplate1}">
            <StackPanel Orientation="Horizontal" >
<Image Source="/DocumentLibrarySL;component/Images/Folder.png"/>
<TextBlock Text="{Binding Title}" />
</StackPanel>
</telerik:HierarchicalDataTemplate>


1 Answer, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 28 Feb 2011, 12:43 PM
Hi Kartheek,

If you need to set the "ProductTemplate" HiearachicalDataTemplate ItemTemplate property, you can set it like so:
Telerik.Windows.Controls.HierarchicalDataTemplate template = (Telerik.Windows.Controls.HierarchicalDataTemplate)this.Resources["ProductTemplate"];
Telerik.Windows.Controls.HierarchicalDataTemplate template1 = (Telerik.Windows.Controls.HierarchicalDataTemplate)this.Resources["TreeTemplateLevel"];
template.ItemTemplate = template1;

I also noticed that you have set an ItemTemplate for the "ProductTemplate" in XAML, and therefore I was wondering whether you need to dynamically determine which ItemTemplate to use. If this is the case, then you can take advantage of the HierarchicalDataTemplate ItemTemplateSelector property.

I hope that info helps.

Best wishes,
Tina Stancheva
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
TreeView
Asked by
Kartheek
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Share this question
or