Catastrophic failure in setting the itemtemplate using code behind for Treeview

2 posts, 0 answers
  1. Kartheek
    Kartheek avatar
    12 posts
    Member since:
    Dec 2010

    Posted 22 Feb 2011 Link to this post


    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);

    <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"/>
            <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}" />

  2. Tina Stancheva
    Tina Stancheva avatar
    3299 posts

    Posted 28 Feb 2011 Link to this post

    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!
Back to Top