RadTreeViewItem Visibility not Collapsing ItemsPanel space

7 posts, 0 answers
  1. Ben
    Ben avatar
    19 posts
    Member since:
    Aug 2010

    Posted 25 Aug 2010 Link to this post

    I have a treeview where I dynamically change the Visibility of the RadTreeViewItem that is added to the the tree.  Unfortuantely the ItemsPresenter of the Parent item seems to be taking up the full space even though some items are not visibility.  Attached is a screenshot of this.

    <UserControl 
        x:Class="Telerik_Q2_2010_Samples.MainPage"
        xmlns:c="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" 
        xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" 
        mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
        <UserControl.Resources>
            <telerik:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        </UserControl.Resources>
          
        <StackPanel x:Name="LayoutRoot" Margin="30">
      
            <c:RadTreeView>
                <c:RadTreeViewItem Header="TestA" IsExpanded="True">
                    <c:RadTreeViewItem Header="Test1" />
                    <c:RadTreeViewItem Header="Test2" Visibility="{Binding IsChecked, ElementName=toggle, Converter={StaticResource BooleanToVisibilityConverter}}" />
                    <c:RadTreeViewItem Header="Test3" />
                    <c:RadTreeViewItem Header="Test4" />
                </c:RadTreeViewItem>
                <c:RadTreeViewItem Header="TestB" />
            </c:RadTreeView>
            
            <ToggleButton x:Name="toggle" Content="Toggle" HorizontalAlignment="Left" />
        </StackPanel>
    </UserControl>


    I'm using the SL3 8/12/2010 build.
  2. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 31 Aug 2010 Link to this post

    Hi Ben,

    Yes, you are right. The parent RadTreeViewItem forms a gap when Visibility property of its child is changed.

    There are several ways to work around the issue and accomplish fluid UI when changing the Visibility property of the RadTreeViewItem:
    1. Change the ItemsPanel property of the RadTreeViewItem via style. This will result in proper resizing of the parent tree view item. But this will disable the implemented virtualization in the default item panel (TreeViewPanel). Meaning that virtualization of the tree will not work. This approach is applicable if you won't need the virtualization and your tree view is relatively small.
    2. Change the underling data collection itself instead manipulating the Visibility property of the RadTreeViewitem. In this scenario you will need to use data binding and remove/add elements in the data source. This approach is applicable when you have relatively big tree (also consider using virtualization and load on demand).

    I'm attaching a sample project demonstrating both approaches. You can take a look at the MainPage files and play around with commented code fragments. I hope this info will help you solve the issue you are experiencing. If you require more info don't hesitate to contact us.

    All the best,
    Hristo Milyakov
    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. DevCraft banner
  4. Ben
    Ben avatar
    19 posts
    Member since:
    Aug 2010

    Posted 31 Aug 2010 Link to this post

    I only have about 100 rows max.  Changing the ItemsPanel to a StackPanel worked for me.

    Thanks.
  5. Ville
    Ville avatar
    18 posts
    Member since:
    Apr 2010

    Posted 08 Dec 2010 Link to this post

    Has the solution #1 been implemented in the latest DLLs?
  6. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 09 Dec 2010 Link to this post

    Hello Giuliano,

    The first solution is custom code you should implement yourself. We can not change the TreeViewPanel with StackPanel because this will disable the virtualization features of the tree for all control users.

    Let me know if you need more info on the topic.

    Greetings,
    Hristo
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  7. Murray
    Murray avatar
    121 posts
    Member since:
    Aug 2010

    Posted 29 Aug 2011 Link to this post

    Is there a way to collapse the visibility of the parent node items? Your sample is for SubEntities.
  8. Murray
    Murray avatar
    121 posts
    Member since:
    Aug 2010

    Posted 29 Aug 2011 Link to this post

    Never mind I figured it out.
Back to Top
DevCraft banner