Highlight TreeviewItem based on text size

6 posts, 2 answers
  1. Rajesh
    Rajesh avatar
    15 posts
    Member since:
    Jan 2013

    Posted 04 Jan 2013 Link to this post

    My customer would like to see the item highlighted based on the text size when selecting an item in the tree.

    I have attached the file. Please take a look at it.

    Your help is much appreciated. Thanks in advance.

    Regards,
    Rajesh.B

  2. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 07 Jan 2013 Link to this post

    Hello Rajesh,

    By default the RadTreeViewItem HorizontalAlignment is set to Stretch thus taking all available space inside the RibbonView control. In order to change this behavior to make the item take up only as much space as its Header content needs, you can set the HorizontalAlignment to Left:
    <Style TargetType="telerik:RadTreeViewItem">
        <Setter Property="HorizontalAlignment" Value="Left" />
    </Style>

    Please give this a try and let us know if you need further info.

    Regards,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Rajesh
    Rajesh avatar
    15 posts
    Member since:
    Jan 2013

    Posted 07 Jan 2013 Link to this post

    Thanks much Tina.

      You suggestion works great.

    I had set the "HorizontalContentAlignment" to Left. But not the "HorizontalAlignment".

    <Setter Property="HorizontalContentAlignment" Value="Left" />


  5. Rajesh
    Rajesh avatar
    15 posts
    Member since:
    Jan 2013

    Posted 23 Jan 2013 Link to this post

    <Style x:Key="RADTreeViewItemStyle" TargetType="telerik:RadTreeViewItem">
        <Setter Property="HorizontalAlignment" Value="Left"/>
        <Setter Property="CheckState" Value="Off" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Padding" Value="1 0 5 0" />
        <Setter Property="IsDropAllowed" Value="True" />
        <Setter Property="ItemsOptionListType" Value="Default" />
        <Setter Property="IsEnabled" Value="True" />
        <Setter Property="MinHeight" Value="24" />               
        <Setter Property="Template" Value="{StaticResource TreeViewItemDefaultTemplate}" />
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <telerik:TreeViewPanel VerticalAlignment="Bottom" />
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    Here is something my customer came across.

    Setting "HorizontalContentAlignment" to "Left" really works.

    But it works only when the child nodes are collapsed. If the the node is expanded, the highlight stretch to the extent of max width in the child node.

    Please take a look at the attached file for better understanding.

    I have also attached the <Style> tag that I use for this Treeview.

    I greatly appreciate your response.

    Thanks,
    Rajesh.B

  6. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 24 Jan 2013 Link to this post

    Hi Rajesh,

    This is the expected behavior of the control. When working with the RadTreeViewItems, you need to have in mind that their ControlTemplate has a Header and an Items part - in the header part you can find a ContentPresenter that represents the header part of the control, while the Items part is basically the ItemsPresenter that displays the children of the item.

    This means that the Width of one RadTreeViewItem is determined by the length of its header as well as by the length of the header of each one of its children. This is what is causing the issue in your case - when you expand the item, its children are displayed and the Width of the item is expanded to display all children of the item.

    I hope this information helps you better understand the behavior of the control.

    Kind regards,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  7. Rajesh
    Rajesh avatar
    15 posts
    Member since:
    Jan 2013

    Posted 24 Jan 2013 Link to this post

    Thanks much!!

    I swear I had this thought before i spell out that to my customer. But would like to proof them by you guys.

    Thank you very much for the support. I do really appreciate!
Back to Top
DevCraft banner