ExpandItemByPath broken ?

4 posts, 0 answers
  1. hwsoderlund
    hwsoderlund avatar
    419 posts
    Member since:
    Aug 2006

    Posted 28 Jul 2009 Link to this post

    Hi, take a look at the following. Nothing happens when I do ExpandItemByPath.

    <UserControl x:Class="TreeViewExpandByPath.SilverlightControl2" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
                 xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" 
                 xmlns:nav="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" 
        Width="400" Height="300"
        <Grid x:Name="LayoutRoot" Background="White"
            <nav:RadTreeView x:Name="treeView"
                <nav:RadTreeView.Items> 
                    <nav:RadTreeViewItem> 
                        <nav:RadTreeViewItem.Header> 
                            <TextBlock Text="Item 1"></TextBlock> 
                        </nav:RadTreeViewItem.Header> 
                    </nav:RadTreeViewItem> 
                    <nav:RadTreeViewItem> 
                        <nav:RadTreeViewItem.Header> 
                            <TextBlock Text="Item 2"></TextBlock> 
                        </nav:RadTreeViewItem.Header> 
                        <nav:RadTreeViewItem.Items> 
                            <nav:RadTreeViewItem> 
                                <nav:RadTreeViewItem.Header> 
                                    <TextBlock Text="Item 2 - 1"></TextBlock> 
                                </nav:RadTreeViewItem.Header> 
                                <nav:RadTreeViewItem.Items> 
                                    <nav:RadTreeViewItem> 
                                        <nav:RadTreeViewItem.Header> 
                                            <TextBlock Text="Item 2 - 1 - 1"></TextBlock> 
                                        </nav:RadTreeViewItem.Header> 
                                    </nav:RadTreeViewItem> 
                                    <nav:RadTreeViewItem> 
                                        <nav:RadTreeViewItem.Header> 
                                            <TextBlock Text="Item 2 - 1 - 2"></TextBlock> 
                                        </nav:RadTreeViewItem.Header> 
                                    </nav:RadTreeViewItem> 
                                </nav:RadTreeViewItem.Items> 
                            </nav:RadTreeViewItem> 
                            <nav:RadTreeViewItem> 
                                <nav:RadTreeViewItem.Header> 
                                    <TextBlock Text="Item 2 - 2"></TextBlock> 
                                </nav:RadTreeViewItem.Header> 
                            </nav:RadTreeViewItem> 
                        </nav:RadTreeViewItem.Items> 
                    </nav:RadTreeViewItem> 
                    <nav:RadTreeViewItem Header="Item 3"></nav:RadTreeViewItem> 
                </nav:RadTreeView.Items> 
            </nav:RadTreeView> 
        </Grid> 
    </UserControl> 
     

    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Net; 
    using System.Windows; 
    using System.Windows.Controls; 
    using System.Windows.Documents; 
    using System.Windows.Input; 
    using System.Windows.Media; 
    using System.Windows.Media.Animation; 
    using System.Windows.Shapes; 
     
    namespace TreeViewExpandByPath 
        public partial class SilverlightControl2 : UserControl 
        { 
            public SilverlightControl2() 
            { 
                InitializeComponent(); 
     
                this.Dispatcher.BeginInvoke(() => treeView.ExpandItemByPath("Item 2|Item 2 - 1|Item 2 - 1 - 1""|")); 
            } 
        } 
     

    The weird thing is that if I specify the Header property directly on the TreeViewItem (<nav:RadTreeViewItem Header="whatever" />) instead of breaking it out and explicitly creating a TextBlock, everything works fine. But I need more than text in my tree nodes.


  2. Bobi
    Admin
    Bobi avatar
    513 posts

    Posted 29 Jul 2009 Link to this post

    Hello hwsoderlund,

    The ExpandItemByPath functionality works by creating a path from the string representations of the Headers.
    So I changed your code in the following way and everything works as expected:

    <nav:RadTreeView x:Name="treeView">
                        <nav:RadTreeViewItem Header="Item 1"/>
                        <nav:RadTreeViewItem Header="Item 2">
                                <nav:RadTreeViewItem Header="Item 2 - 1">
                                        <nav:RadTreeViewItem Header="Item 2 - 1 - 1"/>
                                        <nav:RadTreeViewItem Header="Item 2 - 1 - 2"/>
                                </nav:RadTreeViewItem>
                                <nav:RadTreeViewItem Header="Item 2 - 2"/>
                        </nav:RadTreeViewItem>
                        <nav:RadTreeViewItem Header="Item 3"/>
                </nav:RadTreeView>

    There is no need to use  a construction like this if you want just to set some text header:
    <nav:RadTreeView.Items>
                    <nav:RadTreeViewItem>
                        <nav:RadTreeViewItem.Header>
                            <TextBlock Text="Item 1"></TextBlock>
                        </nav:RadTreeViewItem.Header>
                    </nav:RadTreeViewItem>
    You can simply write something like:

    <nav:RadTreeView x:Name="treeView">
                        <nav:RadTreeViewItem Header="Item 1"/>

    I hope that this will help you.

    All the best,
    Boryana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
  4. hwsoderlund
    hwsoderlund avatar
    419 posts
    Member since:
    Aug 2006

    Posted 29 Jul 2009 Link to this post

    But I don't want just a text header. I have lots of other stuff in my tree items as well as text, like checkboxes, images etc. The code I posted is just a simple example to demonstrate the bug. And I'm pretty sure that this used to work just fine, but it doesn't work anymore. Surely it must be possible to parse through the content of the tree items, parse out the actual text (for instance if there's a CheckBox, just get the content of that and ToString() it) and then use that text to construct the path?
  5. Bobi
    Admin
    Bobi avatar
    513 posts

    Posted 30 Jul 2009 Link to this post

    Hello hwsoderlund,

    We apologize for the caused inconvenience.
    For now RadTreeView does not support this scenario when using RadTreeviewItem without some ItemTemplate , however we deeply appreciate your suggestion and this functionality will be added as soon as possible. Your telerik points are updated.

    If you want to accomplish the desired functionality you can use  ItemTemplate / ItemTemplateSelector /ItemContainerStyle  in order to customize the appearance of the items.
    Please find attached a sample project.

    I hope that this will help you.

    Regards,
    Boryana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top