Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > TreeView > Expand all on load

Answered Expand all on load

Feed from this thread
  • John avatar

    Posted on Jan 11, 2012 (permalink)

    Hello,
    Im pretty new to silverllight. I have a radTreeView and all I want to do is Expand all the nodes on the tree when the page loads. I have been trying this with ContainerBinding collection like this:>
    <telerik:ContainerBindingCollection x:Name="BindingsCollection">
        <telerik:ContainerBinding PropertyName="IsExpanded" Binding="{Binding Expanded, Mode=TwoWay}" />
    </telerik:ContainerBindingCollection>
            >
     
        <telerik:RadTreeView telerik:StyleManager.Theme="Office_Blue" Name="CounterpartyTree" ItemsSource="{Binding CounterpartySource}" SelectedItem="{Binding CounterTreeSelection, Mode= TwoWay}" IsSingleExpandPath="False" IsExpandOnSingleClickEnabled="True" IsExpandOnDblClickEnabled="False">
            <telerik:RadTreeView.ItemTemplate>
                    <telerik:HierarchicalDataTemplate ItemsSource="{Binding companyDivisions}" telerik:ContainerBinding.ContainerBindings="{StaticResource BindingsCollection}" >
                        <TextBlock Text="{Binding CompanyName}" />
                </telerik:HierarchicalDataTemplate>
            </telerik:RadTreeView.ItemTemplate>
        </telerik:RadTreeView>
    I have an expanded property on the viewmodel, and I just set it to true on new..( I dont really know what to do with it. ) :/
    It is giving me no results... I tried the same thing with setting the style which also gave me no results.
    <Style x:Key="myItemContainerStyle" TargetType="telerik:RadTreeViewItem">
            <Setter Property="Foreground" Value="Red"/>
            <Setter Property="IsExpanded" Value="True"/>
        </Style>
    and I tried ExpandAll() also. It seems like Im missing something, I feel this should be something pretty easy to do.

    Thanks in advance for the help!

    Reply

  • Answer Petar Mladenov Petar Mladenov admin's avatar

    Posted on Jan 16, 2012 (permalink)

    Hi John,

    I'll start backwards. Style Binginds won't work in Silverlight 4, but they will work in SL 5. If you use SL 4 , the ContainerBindigns is what you need. You have configured them well, but I can see that you haven't defined ItemTemplate for the second tree level:

    <telerik:RadTreeView.ItemTemplate>
                    <telerik:HierarchicalDataTemplate ItemsSource="{Binding companyDivisions}" telerik:ContainerBinding.ContainerBindings="{StaticResource BindingsCollection}" >
                        <TextBlock Text="{Binding CompanyName}" />
                </telerik:HierarchicalDataTemplate>
    This code means that you companysDivisions'Template will be the same as the defined HierarchicalDatatemplate and your companyDivisions must have CompanyName property. Is this your intention? If not, you can use the ItemTemplate property of the telerik's HierarChicalDataTemplate. It will point to the second tree level's Template.
     You can find a possible approach demonstrated in the attached solution. Please let us know if it helps you or not. 

    All the best,
    Petar Mladenov
    the Telerik team

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

    Reply

  • John avatar

    Posted on Jan 20, 2012 (permalink)

    Thanks! the attachment helped me a lot!
    On a related note, is it possible to make the treeview scroll to the selected item?

    Reply

  • Petar Mladenov Petar Mladenov admin's avatar

    Posted on Jan 21, 2012 (permalink)

    Hello John,

     Yes, it is possible. The best method to achieve this is RadTreeView.BringPathIntoView(). Please check out this blog post demonstrating how to use it.

    Regards,
    Petar Mladenov
    the Telerik team

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

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > TreeView > Expand all on load
Related resources for "Expand all on load"

Silverlight TreeView Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]