Expand Tree Node via Code

2 posts, 0 answers
  1. Joel Palmer
    Joel Palmer avatar
    164 posts
    Member since:
    May 2009

    Posted 07 Oct Link to this post

    I have a simple RadTreeView that is defined like this:

     

    <telerik:RadTreeView
        x:Name="contextTree"
        Margin="8"
        ItemsSource="{Binding Hierarchy, Mode=TwoWay}">
        <telerik:RadTreeView.ItemTemplate>
            <HierarchicalDataTemplate
                ItemsSource="{Binding Children}">
                <TextBlock Text="{Binding Name}" />
            </HierarchicalDataTemplate>
        </telerik:RadTreeView.ItemTemplate>
    </telerik:RadTreeView>

     

    My Hierarchy is an ObservableCollection of a HierarchyContext object that has an ID, Name, Role, ParentID and Children properties.

    I would like to have all nodes in the collection Expanded by default.  I'd also like to be able to control if each node is expanded through Code.  I assume I'd need to add a "IsExpanded" bool? property to my object but, can you give me an example of how to do this? 

    Thanks, Joel.

     

     

  2. Joel Palmer
    Joel Palmer avatar
    164 posts
    Member since:
    May 2009

    Posted 07 Oct Link to this post

    Never Mind.  I found this.

    <Style TargetType="telerik:RadTreeViewItem">
        <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
    </Style>

     

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top