How to set the treeview middle model IsExpanded?

1 Answer 16 Views
TreeView
Psyduck
Top achievements
Rank 4
Bronze
Bronze
Iron
Psyduck asked on 21 May 2021, 09:26 AM | edited on 21 May 2021, 09:27 AM

Hello.

 

How do I set up the expanded configuration of the Treeview middle model only?

<telerik:RadTreeView.Resources>
	<Style TargetType="telerik:RadTreeViewItem" BasedOn="{StaticResource RadTreeViewItemStyle}">
		<Setter Property="IsExpanded" Value="True"/>
	</Style>
</telerik:RadTreeView.Resources>

This is true for all of the lower layers.

When I first opened it, I only want to open it up to the middle level. (Attach an image)

Thanks.

 

1 Answer, 1 is accepted

Sort by
1
Accepted
Martin Ivanov
Telerik team
answered on 25 May 2021, 03:17 PM

Hello KIM,

To achieve your requirement, you can define a new bool property in the tree view item models, like SubB, SubA and MainModel. Then you can data bind this property to the IsExpanded of the RadTreeViewItem. You can use the model's property in order to control the expand state of the corresponding items. Here is an example in code:

public class SubA : ViewModelBase
{
	private bool isExpanded;

	public bool IsExpanded
	{
		get { return isExpanded; }
		set 
		{
			isExpanded = value;
			OnPropertyChanged("IsExpanded");
		}
	}
	// other properties here
}

<telerik:RadTreeView.Resources>
	<Style TargetType="telerik:RadTreeViewItem" BasedOn="{StaticResource RadTreeViewItemStyle}">
		<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
	</Style>
</telerik:RadTreeView.Resources>

I hope this helps.

Regards,
Martin Ivanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
TreeView
Asked by
Psyduck
Top achievements
Rank 4
Bronze
Bronze
Iron
Answers by
Martin Ivanov
Telerik team
Share this question
or