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

Controlling TreeViewItems visibility with binding.

2 Answers 116 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Lisa
Top achievements
Rank 1
Lisa asked on 22 Jun 2011, 06:03 PM

Hi – I have a TreeView that contains TreeViewItems for different filtering areas.  It’s in a User Control that can be used by several charts.  I want to control which TreeViewItems are visible or collapsed depending on what the chart needs.


I’ve seen and done examples bound to things like a button or checkbox, but I want this to be behind the scenes, no user interaction needed.  My thought is that I set a Boolean in the code-behind and the TreeViewItem is bound to that.  Is that possible?  If so, how can I do it?

Here is an example of what I have working when a checkbox is selected, so I think my Visibility Converter is working:

 

<CheckBox x:Name="ckShowSub" Content="Show Subject" HorizontalAlignment="Left" Margin="30,5,5,5" />

 
<telerik:RadTreeViewItem x:Name="tviWsaSubject" Header="Subject"

    ItemsSource="{Binding SubjectLists}" 
    ItemsOptionListType="CheckList" 
    ItemTemplate="{StaticResource WsaSubjectTreeViewTemplate}" 
    Visibility="{Binding Path=IsChecked, ElementName=ckShowSub, Converter={StaticResource visibilityConverter}}"/>

 

Thank You!

2 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 27 Jun 2011, 04:44 PM
Hi Lisa,

Yes this is possible with implementing ViewModels. If you bind the RadTreeView to a Collection of ViewModels, you can bind a boolean or property of type Visibility from the model to the Visibility property of the RadTreeViewItem via ContainerBindings. Keep in mind that there are some issues when you bind this property and your tree is Virtualized. So if you don't use too much items, it's better to turn this off. 
Let us know if you need assistance on this. 

Best wishes,
Petar Mladenov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Lisa
Top achievements
Rank 1
answered on 27 Jun 2011, 04:46 PM
Thank you!
Tags
TreeView
Asked by
Lisa
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Lisa
Top achievements
Rank 1
Share this question
or