Skip to content

xueyuhuanying/VirtualTreeView

 
 

Repository files navigation

VirtualTreeView

A WPF TreeView that actually supports virtualization.
Works with .NET Framework 4.5.

How to use it

It is available as a NuGet package.
The source code includes a demonstration application, where both modes (content and binding) are showed, side-by-side to traditional TreeView control.

The treeview itself

It works exactly as the original TreeView (with a lot of missing features...):

<vtv:VirtualTreeView ItemsSource="{Binding Items}">
    <!-- Item style, if there is only one, can also be set using the ItemStyle property -->
    <vtv:VirtualTreeView.Resources>
        <!-- The important stuff here is the ItemsSource -->
        <HierarchicalDataTemplate ItemsSource="{Binding Children}" 
                                  DataType="{x:Type my:ViewModels}">
            <Grid>
                <TextBlock Text="{Binding MyLabel}"/>
            </Grid>
        </HierarchicalDataTemplate>
    </vtv:VirtualTreeView.Resources>
    <!-- This is optional if you want to bind the IsExpanded property -->
    <vtv:VirtualTreeView.ItemContainerStyle>
        <Style TargetType="{x:Type vtv:VirtualTreeViewItem}">
            <Setter Property="IsExpanded" Value="{Binding MyIsExpanded, Mode=TwoWay}" />
        </Style>
    </vtv:VirtualTreeView.ItemContainerStyle>
</vtv:VirtualTreeView>

The treeview item

If you move from an existing treeView, you'll need to copy/paste your TreeViewItem style and adapt it to vtv:TreeViewItem (usually no change is required, except removing the hierarchical part, which is generated when the control converts the tree to a list).

What does work

Currently it has only the features I needed (which is showing items and let them live); all contributors are welcome. The goal is to have a complete and extensible tree view.

  • With binding, INotifyCollectionChanged fully works, so you can dynamically change content by adding or removing elements at any point of the hierarchy.

What does not

  • With binding, INotifyPropertyChanged does not work at all, since the binding is partly simulated (because the view items are not generated).

How to contribute

Fork it, update it, and submit your pull requests.
Alternatively you can submit requests.

About

A WPF TreeView that actually supports virtualization.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%