Controlling TreeViewItems visibility with binding.

3 posts, 0 answers
  1. Lisa
    Lisa avatar
    37 posts
    Member since:
    May 2011

    Posted 22 Jun 2011 Link to this post

    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}" 
        ItemTemplate="{StaticResource WsaSubjectTreeViewTemplate}" 
        Visibility="{Binding Path=IsChecked, ElementName=ckShowSub, Converter={StaticResource visibilityConverter}}"/>


    Thank You!

  2. Petar Mladenov
    Petar Mladenov avatar
    3162 posts

    Posted 27 Jun 2011 Link to this post

    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
  3. Lisa
    Lisa avatar
    37 posts
    Member since:
    May 2011

    Posted 27 Jun 2011 Link to this post

    Thank you!
Back to Top