Coffeehouse Thread

5 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Custom Winform TreeListView to WPF TreeListView - Help!!

Back to Forum: Coffeehouse
  • User profile image
    BitFlipper

    I'm quite familiar with WinForms and have a custom TreeListView that is highly optimized for speed (tested with 1 million nodes with barely any noticeable slowdown).

    OK, now I am writing a Visual Studio plugin (VSPackage) and would like to switch to a WPF TreeListView. I'm currently hosting my custom WinForms TreeListView inside a WinFormsHost in order to display it as a Visual Studio tools window. However for various reasons I need to not use that so instead I want to use a true WPF TreeListView. I realize there is no WPF TreeListView per se, but WPF is supposedly flexible enough that you can create a TreeListView. If you know how.

    I'm not that familiar with WPF and XAML so this is a bit of a challenge for me. I looked at the sample linked from this page, but there is minimal code and it isn't clear how the tree and columns relate. I can't even figure out if the TreeView is nested inside the Grid or what the relationship is there. Unfortunately that sample doesn't add the nodes programmatically so to go from the XAML to C# code isn't too obvious.

    This is what I need:

    • Ability to programmatically create columns.
    • Ability to programmatically add/remove nodes.
    • Nodes need to be virtual, and data should only be requested when the node comes into view, or if it has been expanded.
    • Ability to invalidate nodes so that their data is re-requested without deleting the node.
    • Ability to know the index of the top visible row.
    • Ability to know the number of rows that will fit in the TreeListView at one time.
    • Ability to format the contents of each node/column (font color, bold, etc).
    • It should be fast. I've heard horror stories of the WPF TreeView choking on 5000 items. I know it has a virtual mode but with my past WPF experience I'm not expecting too much in the performance department. As a reference, the way that I currently use my TreeListView in the VS plugin is that I take samples about 10 times per second, then remove all nodes and re-construct the tree from scratch. This happens without any visual glitches and for a few thousand nodes, this takes less than 1 millisecond.

    Any suggestions?

  • User profile image
    BitFlipper

    I found this. Currently investigating...

  • User profile image
    Dr Herbie

    @BitFlipper: If you get really desperate, you can host Winforms controls in WPF so you could use your existing control for the time-being while you figure out it's replacement.

     

  • User profile image
    RealBboy360
  • User profile image
    BitFlipper

    Thanks for the info guys, this is an old thread :)

    I have since learned how to do it the "WPF way" and did it properly in WPF using templates, bindings, converters, triggers, etc. However I ran into severe performance issues with the WPF TreeView and large collections. The problem is that TreeView can do UI virtualization but not data virtualization.

    So I ended up creating a custom WPF TreeListView control based on ListView. It is bound to a flat<->hierarchical collection that implements INotifyCollectionChanged and solves the performance issues nicely by also implementing data virtualization efficiently.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.