Click here to Skip to main content
15,896,330 members
Articles / Desktop Programming / WPF

A Versatile TreeView for WPF

Rate me:
Please Sign up or sign in to vote.
4.95/5 (107 votes)
7 Feb 2008CPOL15 min read 642.3K   18.6K   303  
A strongly typed enhancement of the regular WPF TreeView control.
// hardcodet.net WPF TreeView control
// Copyright (c) 2008 Philipp Sumi, Evolve Software Technologies
// Contact and Information: http://www.hardcodet.net
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the Code Project Open License (CPOL);
// either version 1.0 of the License, or (at your option) any later
// version.
// 
// This software is provided "AS IS" with no warranties of any kind.
// The entire risk arising out of the use or performance of the software
// and source code is with you.
//
// THIS COPYRIGHT NOTICE MAY NOT BE REMOVED FROM THIS FILE.


using System.Windows;

namespace Hardcodet.Wpf.GenericTreeView
{

  /// <summary>
  /// Event handler signature for the
  /// <see cref="TreeViewBase{T}.SelectedItemChangedEvent"/>
  /// routed event.
  /// </summary>
  /// <typeparam name="T">The type of the tree's items.</typeparam>
  /// <param name="sender">The event source.</param>
  /// <param name="e">Provides both new and old processed item.</param>
  public delegate void RoutedTreeItemEventHandler<T>(object sender, RoutedTreeItemEventArgs<T> e) where T : class;

  /// <summary>
  /// Event arguments for the <see cref="TreeViewBase{T}.SelectedItemChangedEvent"/>
  /// routed event.
  /// </summary>
  /// <typeparam name="T">The type of the tree's items.</typeparam>
  public class RoutedTreeItemEventArgs<T> : RoutedEventArgs where T : class
  {
    private readonly T newItem;
    private readonly T oldItem;

    /// <summary>
    /// The currently selected item that caused the event. If
    /// the tree's <see cref="TreeViewBase{T}.SelectedItem"/>
    /// property is null, so is this parameter.
    /// </summary>
    public T NewItem
    {
      get { return newItem; }
    }


    /// <summary>
    /// The previously selected item, if any. Might be null
    /// if no item was selected before.
    /// </summary>
    public T OldItem
    {
      get { return oldItem; }
    }


    /// <summary>
    /// Creates the event args.
    /// </summary>
    /// <param name="newItem">The selected item, if any.</param>
    /// <param name="oldItem">The previously selected item, if any.</param>
    public RoutedTreeItemEventArgs(T newItem, T oldItem)
      : base(TreeViewBase<T>.SelectedItemChangedEvent)
    {
      this.newItem = newItem;
      this.oldItem = oldItem;
    }

  }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect I'm a gun for hire
Switzerland Switzerland
Philipp is an independent software engineer with great love for all things .NET.
He lives in Winterthur, Switzerland and his home on the web is at http://www.hardcodet.net.

Comments and Discussions