Selective Visibility of nodes

3 posts, 1 answers
  1. christina noel
    christina noel avatar
    42 posts
    Member since:
    Mar 2010

    Posted 27 Jan 2012 Link to this post


    I'm binding a virtualized RadTreeView to a (hierarchichal) ObservableCollection of a custom object.

    One of the fields on the custom object is "Active" (boolean).

    There is a toggle button on my user control that is supposed to control whether all of the objects show in the treeview or if only "Active" objects show.

    I'm having several problems:
    1) For an initial test, I tried just assuming that the toggle button is set to "Active only", and tried using container bindings to hide the items, but this seemed to have no effect. (The code I'm currently using is shown below).
    2) I have no idea how to turn the container bindings on and off based on the toggle button.
    3) The same observable collection is bound to a BreadcrumbBar, which needs to behave similarly to the treeview.

    I'm willing to take another approach entirely, if that will be better. I'm even willing to change the item's source entirely if you can recommend a way to filter without having to traverse the whole tree.


        <telerik:ContainerBindingCollection x:Key="FolderBindings">
            <telerik:ContainerBinding PropertyName="Visible" Binding="{Binding Active, Converter={StaticResource BooleanToVisibilityConverter}}"/>
    <telerik:RadTreeView x:Name="tvFolders"  Grid.Row="1" LoadOnDemand="tvFolders_LoadOnDemand"  IsLoadOnDemandEnabled="true"
                         telerik:StyleManager.Theme="{StaticResource MPTheme}"
                         Background="White" ItemsSource="{Binding Source={StaticResource FolderSource}, Path=FolderNodes}"
                         SelectionChanged="tvFolders_SelectionChanged" BringIntoViewMode="HeaderAndItems" IsVirtualizing="true"
                         telerik:RadDragAndDropManager.AllowDrop="True" >
            <telerik:RadContextMenu Opened="FolderContextMenu_Opened" ItemClick="FolderContextMenu_ItemClick" ItemsSource="{StaticResource TVFolderContextMenuItems}" />
        <telerik:RadTreeView.ItemTemplate >
            <telerik:HierarchicalDataTemplate  ItemsSource="{Binding ChildFolders}" telerik:ContainerBinding.ContainerBindings="{StaticResource FolderBindings}" >
                <TextBlock Text="{Binding Name}">
                            <TextBlock Text="{Binding Name}" />
  2. Answer
    Petar Mladenov
    Petar Mladenov avatar
    3162 posts

    Posted 01 Feb 2012 Link to this post

    Hello Christina Noel ,

    You can see why your ContainerBindingsCollection does not work by checking the output for BindingExpression Errors.
    I believe it is the wrong named property - you have typed Visible but the property of the RadTreeViewItem is Visibility. However there is a bug our RadTreeView that will stop you from using this approach:
    TreeView: The TreeViewPanel keeps the space for the collapsed items
    What we could suggest you is to filter your viewmodels when needed and assign new ItemsSource to the RadTreeView - this way you will workaround the mentioned bug. Is this suitable for you?

    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. christina noel
    christina noel avatar
    42 posts
    Member since:
    Mar 2010

    Posted 01 Feb 2012 Link to this post

    We've decided (for the time being) to just not include inactive objects in the ItemsSource for the treeview and breadcrumb bar. I've added to the votes for the bug you linked, and have started tracking it so that we can revisit this problem when the bug is resolved.

    Thank you!
Back to Top