Silverlight Feeds - All your Silverlight feeds in one place.

Sponsors

Thursday, May 14, 2009

Auto expanding tree view for Silverlight

by StefanOlson via Stefan Olson's Blog on 5/14/2009 12:30:52 PM

Bea Stollnitz has been running a series on her blog, describing how to expand items in the tree view, in both WPF and Silverlight, but much of it was extraordinarily complicated.   For the project I'm working on with Silverlight and the .net RIA services I needed one of my tree views to appear completely expanded initially.  There's a lot of code on Bea’s blog, but I cut down what I needed to this new tree view control.  You can use it in your application and your tree will initially be completely expanded:

public class AutoExpandingTreeViewItem : TreeViewItem
{
    protected override DependencyObject GetContainerForItemOverride()
    {
        return new AutoExpandingTreeViewItem { IsExpanded = true };
    }
}
public class AutoExpandingTreeView : TreeView
{
    protected override DependencyObject GetContainerForItemOverride()
    {
        return new AutoExpandingTreeViewItem { IsExpanded = true };
    }
}

Here's how you would use it in your page:

<UserControl x:Class="HireMyStuffAdmin.SilverlightControl1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:toolkit="clr-namespace:System.Windows;assembly=System.Windows.Controls" 
    xmlns:controls="clr-namespace:OlsonSoftware.controls" 
    Width="400" Height="300">
    <Grid x:Name="LayoutRoot" Background="White">
        <controls:AutoExpandingTreeView ItemsSource="{Binding Categories}">
            <controls:AutoExpandingTreeView.ItemTemplate>
                <toolkit:HierarchicalDataTemplate  ItemsSource="{Binding ChildCategories}">
                    <StackPanel >
                        <TextBlock Text="{Binding Name}"></TextBlock>
                    </StackPanel>
                </toolkit:HierarchicalDataTemplate>
            </controls:AutoExpandingTreeView.ItemTemplate>
        </controls:AutoExpandingTreeView>
    </Grid>
</UserControl>
email it!bookmark it!digg it!

Original Post: Auto expanding tree view for Silverlight

Subscribe

New Feed

Product Spotlight

Recently Updated Sources

Legal Note

The content of the postings is owned by the respective author. Silverlight Feeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on Silverlight Feeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.

Advertise with us