wrap treeview node text

2 posts, 1 answers
  1. Kevin
    Kevin avatar
    24 posts
    Member since:
    Apr 2011

    Posted 14 Dec 2011 Link to this post

    hi

    I have a treeview in a stackpanel which can expand or shrink base on some logic. is it possible to limited the maxlenght of the treeview node text so that the text will wrap instread of the horizontal scrollbar shows up when the text is longer than the initial length of the treeview?

    Thanks

    Kevin
  2. Answer
    Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 19 Dec 2011 Link to this post

    Hello Kevin,

     You can set MaxWidth of the RadTreeViewitems via Style and then you can use TextBlocks for the Headers. You need to set the TextWrapping property of the TextBlocks to "Wrap", for  example like so:

    <Grid x:Name="LayoutRoot" Background="White">
            <Grid.Resources>
                <Style TargetType="telerik:RadTreeViewItem">
                    <Setter Property="MaxWidth" Value="290" />
                </Style>
                <DataTemplate x:Key="itemtemplate">
                    <TextBlock TextWrapping="Wrap" Text="{Binding Name}" />
                </DataTemplate>
            </Grid.Resources>
     
            <telerik:RadTreeView x:Name="tree" ItemTemplate="{StaticResource itemtemplate}" Width="300" Background="AliceBlue"/>
     
        </Grid>
    You can find this realized in the attached project. Please let us know if it satisfies you. Regards,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
Back to Top