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

Highlight TreeviewItem based on text size

5 Answers 68 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Rajesh
Top achievements
Rank 1
Rajesh asked on 04 Jan 2013, 08:30 PM

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

5 Answers, 1 is accepted

Sort by
0
Accepted
Tina Stancheva
Telerik team
answered on 07 Jan 2013, 10:34 AM
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.

0
Rajesh
Top achievements
Rank 1
answered on 07 Jan 2013, 04:59 PM
Thanks much Tina.

  You suggestion works great.

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

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


0
Rajesh
Top achievements
Rank 1
answered on 23 Jan 2013, 08:40 PM
<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

0
Accepted
Tina Stancheva
Telerik team
answered on 24 Jan 2013, 05:20 PM
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.

0
Rajesh
Top achievements
Rank 1
answered on 25 Jan 2013, 04:31 AM
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!
Tags
TreeView
Asked by
Rajesh
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Rajesh
Top achievements
Rank 1
Share this question
or