Click here to Skip to main content
15,881,248 members
Articles / Desktop Programming / WPF

WPF TreeListView Control

Rate me:
Please Sign up or sign in to vote.
4.90/5 (71 votes)
23 Aug 2012Apache3 min read 442.9K   24.4K   203  
This article describes the usage of custom WPF TreeListView control comparing with basic TreeView
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Aga.Controls.Tree;

namespace TestApp
{
	/// <summary>
	/// Interaction logic for MainDemo.xaml
	/// </summary>
	public partial class MainDemo : UserControl
	{
		public MainDemo()
		{
			InitializeComponent();

			LoadModel(3,5,5);
		}

		private void LoadModel(int c1, int c2, int c3)
		{
			var model = PersonModel.CreateTestModel(c1, c2, c3);
			_treeList.Model = model;
			_treeView.ItemsSource = model.Root.Children;
		}

		private void Small_Click(object sender, RoutedEventArgs e)
		{
			LoadModel(3, 5, 5);
		}

		private void Big_Click(object sender, RoutedEventArgs e)
		{
			LoadModel(3, 5000, 0);
		}

		private void Toggle_Click(object sender, RoutedEventArgs e)
		{
			foreach(var node in _treeList.SelectedNodes)
				if (node.IsExpandable)
					node.IsExpanded = !node.IsExpanded;
		}

		private void Add_Click(object sender, RoutedEventArgs e)
		{
			if (_treeList.SelectedNode != null)
			{
				var p = new Person() { Name = "NewPerson" };
				(_treeList.SelectedNode.Tag as Person).Children.Add(p);
				_treeList.SelectedNode.IsExpanded = true;
			}
		}

		private void Remove_Click(object sender, RoutedEventArgs e)
		{
			if (_treeList.SelectedNode != null)
			{
				var parent = _treeList.SelectedNode.Parent.Tag as Person;
				var child = _treeList.SelectedNode.Tag as Person;
				parent.Children.Remove(child);
			}
		}
	}
}

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 Apache License, Version 2.0


Written By
Software Developer
Russian Federation Russian Federation
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions