Home > Open Source, WPF TreeView > WPF TreeView Update

WPF TreeView Update

April 7th, 2008

I’ve posted an update for my WPF TreeView which contains a bugfix and two new features:

  • The root item collection is now monitored for changes, and the tree updates itself automatically. This behaviour, however, can be controlled through the ObserveRootItems dependency property.
  • Built-in filtering support through a strongly typed predicate. I’m not completely happy with my implementation though – as a matter of fact, I’ve already started to rewrite it completely – you can expect the next version within the next 10 days. The filtering API however, will remain intact.

In case you did override some of the tree’s virtual methods, your project might not compile out of the box because some of these methods now receive additional parameters. However, as nothing has been removed, adjusting your code should be a matter of seconds.

I’ve added the download link to the original post:
http://www.hardcodet.net/2008/01/wpf-treeview

Happy coding 🙂


Author: Categories: Open Source, WPF TreeView Tags: , ,
  1. Rodolphe
    April 23rd, 2008 at 15:34 | #1

    Hello Philipp,
    Congratulations for your tool … it’s very nice !!!
    I am looking for some advices : I’d like to use your tree to create a hierarchical database explorer (enter data, see data, sort data …). The database is in sql server. What are your suggestions to do that ?
    My main problem concerns the creation of the ObservableColection (from a SQL table) which is mandatory to use your tree. How can I ensure binding between sql/ObservableCollection/tree
    Thank you for your time.
    Rodolphe

  2. April 23rd, 2008 at 15:53 | #2

    Hi Rodolphe,

    You don’t have to use an ObservableCollection – every collection that implements the ICollection interface is ok. However, the tree operates strictly object oriented – if you are working upon relational data, you’ll have to perform some kind of object-relational mapping (mapping of your data on objects, e.g. by writing a TableInfo class that provides information about a given table):
    table row -> object -> tree

    In WPF, a pattern called Model-View-ViewModel is widely adpted. Basically, it means that you provide a convenient object model that plays nicely with your WPF interface:
    http://www.google.com/search?q=wpf%20viewmodel

    Hope that helps – happy coding 🙂
    Philipp

  3. Mr Bin
    July 30th, 2009 at 03:14 | #3

    @Philipp Sumi
    thanks for our tips.

  4. titima
    March 26th, 2010 at 16:25 | #4

    Hi,
    I just want to know if there is an easy way to set/change the image dynamically in the code behind for some nodes.

    Thank you.

  5. xenry
    August 16th, 2010 at 13:34 | #5

    Hi Philipp,

    have you implemented the built-in filtering and multi-selection support? If yes, will you post an update 🙂

  6. October 30th, 2010 at 09:36 | #6

    @xenry
    I’m afraid there’s just no time for that. For now, I’ll only provide bug fixes, should they be required, I’m afraid.

    I’m sorry I don’t have better news for you :/

    Cheers,
    Philipp

  7. Robert Fidler
    January 26th, 2012 at 06:32 | #7

    Very Nice!!!

    New to the WPF world but I have a lot of win forms experience. I’ve been review your code and am trying to add a Multi-Select functionality with no success.

    WinForms extending the control seems easier – I must have a bias.

    Why didn’t you just Extend the TreeView – only asking because I’m a newbie.

    With your code – I’ve added a List SelectedItems collection and added the following logic to the OnSelectedItemPropertyChanged method:
    bool multiselect = ((Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)));

    try
    {
    if (!multiselect)
    SelectedItems.Clear();

    SelectedItems.Add(newValue);
    SelectedItems.ForEach(SelectItemNode);
    }

    The selected item changes but I loose the visual “Selected Item” from the previous selection…

    Any thoughts?
    Thanks for any help.

  1. No trackbacks yet.