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

Expand Tree Node via Code

1 Answer 244 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Joel Palmer
Top achievements
Rank 2
Joel Palmer asked on 07 Oct 2016, 02:30 PM

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.

 

 

1 Answer, 1 is accepted

Sort by
0
Joel Palmer
Top achievements
Rank 2
answered on 07 Oct 2016, 02:51 PM

Never Mind.  I found this.

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

 

Tags
TreeView
Asked by
Joel Palmer
Top achievements
Rank 2
Answers by
Joel Palmer
Top achievements
Rank 2
Share this question
or