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

Expand all on load

3 Answers 133 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
John
Top achievements
Rank 1
John asked on 12 Jan 2012, 01:14 AM
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!

3 Answers, 1 is accepted

Sort by
0
Accepted
Petar Mladenov
Telerik team
answered on 16 Jan 2012, 10:45 AM
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 >>

0
John
Top achievements
Rank 1
answered on 20 Jan 2012, 06:31 PM
Thanks! the attachment helped me a lot!
On a related note, is it possible to make the treeview scroll to the selected item?
0
Petar Mladenov
Telerik team
answered on 21 Jan 2012, 08:50 AM
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 >>

Tags
TreeView
Asked by
John
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
John
Top achievements
Rank 1
Share this question
or