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

Selective Visibility of nodes

2 Answers 85 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
christina noel
Top achievements
Rank 1
christina noel asked on 27 Jan 2012, 07:06 PM
Hi!

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.

--Christina

    <telerik:ContainerBindingCollection x:Key="FolderBindings">
        <telerik:ContainerBinding PropertyName="Visible" Binding="{Binding Active, Converter={StaticResource BooleanToVisibilityConverter}}"/>
 
    </telerik:ContainerBindingCollection>
<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:TextSearch.TextPath="FileElementOID"
                     telerik:RadDragAndDropManager.AllowDrop="True" >
    <telerik:RadContextMenu.ContextMenu>
        <telerik:RadContextMenu Opened="FolderContextMenu_Opened" ItemClick="FolderContextMenu_ItemClick" ItemsSource="{StaticResource TVFolderContextMenuItems}" />
    </telerik:RadContextMenu.ContextMenu>
    <telerik:RadTreeView.ItemTemplate >
        <telerik:HierarchicalDataTemplate  ItemsSource="{Binding ChildFolders}" telerik:ContainerBinding.ContainerBindings="{StaticResource FolderBindings}" >
            <TextBlock Text="{Binding Name}">
                    <ToolTipService.ToolTip>
                        <TextBlock Text="{Binding Name}" />
                    </ToolTipService.ToolTip>
                </TextBlock>
        </telerik:HierarchicalDataTemplate>
    </telerik:RadTreeView.ItemTemplate>
</telerik:RadTreeView>

2 Answers, 1 is accepted

Sort by
0
Accepted
Petar Mladenov
Telerik team
answered on 01 Feb 2012, 03:46 PM
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?

Greetings,
Petar Mladenov
the Telerik team

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

0
christina noel
Top achievements
Rank 1
answered on 01 Feb 2012, 07:21 PM
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!
--Christina
Tags
TreeView
Asked by
christina noel
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
christina noel
Top achievements
Rank 1
Share this question
or