Expand all on load

4 posts, 1 answers
  1. John
    John avatar
    2 posts
    Member since:
    Jan 2012

    Posted 11 Jan 2012 Link to this post

    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!
  2. Answer
    Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 16 Jan 2012 Link to this post

    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 >>

  3. DevCraft banner
  4. John
    John avatar
    2 posts
    Member since:
    Jan 2012

    Posted 20 Jan 2012 Link to this post

    Thanks! the attachment helped me a lot!
    On a related note, is it possible to make the treeview scroll to the selected item?
  5. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 21 Jan 2012 Link to this post

    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 >>

Back to Top