When to call ExpandAll()

5 posts, 1 answers
  1. cecilUOA
    cecilUOA avatar
    20 posts
    Member since:
    May 2007

    Posted 19 Nov 2009 Link to this post

    I would like my tree to be fully expanded by default. So I am looking for a place to put RadTreeListView1.ExpandAll().
    So far I have tested
    • GotFocus - which doesnt get called automatically. 
    • ItemPrepared - which get called on every item in the tree, but expandAll() doesnt expand the first node (the root node). The rest of the tree does fully expanded once I manually expand the root node.
    • Loaded - which fires when the tree control is loaded, not its data.

    I think I understand why ExpandAll() wasnt working for the root node. The tree control binds to just the root node as its ItemsSource. 

    In xmal...

     

    ItemsSource="{Binding TreeListItemsSource}"  

     

     

    In ViewModel...  

    public ObservableCollection<HierarchicalData> TreeListItemsSource { getset; }  

     

    And the TreeListItemsSource only has the root node. The rest of the tree is linked by Items property in each HierarchicalData object.

     

     

     

     

     

     

     

     

     

     

  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 24 Nov 2009 Link to this post

    Hi Doug,

    You can define an ItemContainerStyle and add a setter for the IsExpanded property.

    <Style TargetType="telerikNavigation:RadTreeListViewItem">
        <Setter Property="IsExpanded" Value="True" />
    </Style>

    This way, as soon as the RadTreeListView loads, all of its items will be expanded. Give it a try and let me know how it works for you.

    Greetings,
    Kiril Stanoev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
  4. cecilUOA
    cecilUOA avatar
    20 posts
    Member since:
    May 2007

    Posted 24 Nov 2009 Link to this post

    Thanks for the suggestion.

    However it's still not working. Maybe when RadTreeListView is loaded, the data that it binds to hasnt arrived yet?

    Just to be doubly sure, I should be putting that code inside UserControl.Resources, yes?
  5. Answer
    Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 25 Nov 2009 Link to this post

    Hello Doug,

    You can put the ItemContainerStyle either in the UserControl.Resources:

    <UserControl.Resources>
        <Style x:Key="TreeListItemStyle" TargetType="telerikNavigation:RadTreeListViewItem">
            <Setter Property="IsExpanded" Value="True" />
        </Style>
    </UserControl.Resources>
      
    <Grid x:Name="LayoutRoot">
        <telerikNavigation:RadTreeListView ItemContainerStyle="{StaticResource TreeListItemStyle}" />
    </Grid>

    Or you can put it inline with RadTreeListView's definition:

    <Grid x:Name="LayoutRoot">
        <telerikNavigation:RadTreeListView>
            <telerikNavigation:RadTreeListView.ItemContainerStyle>
                <Style TargetType="telerikNavigation:RadTreeListViewItem">
                    <Setter Property="IsExpanded" Value="True" />
                </Style>
            </telerikNavigation:RadTreeListView.ItemContainerStyle>
        </telerikNavigation:RadTreeListView>
    </Grid>

    However, it is strange that that you are experiencing this issue.
    I am attaching the source code of RadTreeListView's FirstLook example. It demonstrates the IsExpanded functionality. Have a look at it and if you have additonal questions or you find something to be unclear, let me know as soon as possible. I'd be more than happy to assist you.

    Greetings,
    Kiril Stanoev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. cecilUOA
    cecilUOA avatar
    20 posts
    Member since:
    May 2007

    Posted 25 Nov 2009 Link to this post

    I tried having ItemContainerStyle in the UserControl.Resources and reference in my treeListView, and it works. Thank you very much for the help.
Back to Top
DevCraft banner