Gets or sets the suggested height of a FrameworkElement. Gets a value that indicates whether the ItemsControl contains items. Gets a collection of GroupStyle objects that define the appearance of each level of groups. Gets or sets a brush that describes the foreground color. Gets or sets the thickness of the specified font. Gets or sets the style in which the text is rendered. Gets or sets the size of the text in this control. Gets or sets the font used to display text in the control. Gets or sets the context menu element that should appear whenever the context menu is requested through user interface (UI) from within this element. Gets or sets the border thickness of a control. NET 3.0 are included.Gets or sets a brush that provides the background of the control. Project format is currently VS2008 only, but binaries which target. However: The library comes with a sample project that shows pretty much all features of the control. I’m planning to write a CodeProject article for this one, but for now, it’s only available through my place without a tutorial. get the parent category, or null if it's a root category public override ShopCategory GetParentItem(ShopCategory item) returns subcategories that should be available through the tree public override ICollection the sample uses the category's name as the identifier public override string GetItemKey(ShopCategory item) Here’s the complete implementation of the sample application’s tree control: //a tree control that handles only ShopCategory objects public class CategoryTree : TreeViewBase How to access a bound item’s parent, if there is one.How to access a bound item’s childs, if there are any.How to generate an identifier for a given tree node.However, you’ll probably manage with 3 lines of code, as the base control just needs to know 3 things: This means you have to write a little code yourself. AutoCollapse feature / ExpandAll / CollapseAll methodsĪll this goodness comes at a price: The TreeViewBase class that provides this functionality, is abstract.Access to tree nodes (TreeViewItem) through bound items.Tree layout can be cached, saved and reapplied.Simple styling on every level: Tree, TreeViewItem, or bound items (via DataTemplates).Optional root node which is not dependent on the tree’s bound items.Convenient context menu handling for tree nodes.
This allows either virtualized trees in case getting data is expensive, or low memory trees that keep the number of tree nodes at a minimum. Also provides the option to automatically clear invisible tree nodes. Lazy loading support – does not create tree nodes until the parent node is expanded.
SelectedItem is of type Product - no casts required bind flat list of business objects to tree Here’s the tree’s main features at a glance: However, instead of posting a rant that probably nobody would ever read (let alone care about), I worked on an alternative. Furthermore, WPF’s TreeView tends to fire all sorts of SelectedItemChanged events if it’s being refreshed or rebound, which caused side-effects with TwoWay data binding. I became aware of the default control’s limitations during my last project – I naturally started with hierarchical data templates, but was soon confronted with quite a few issues: I missed a simple API to control the tree, and styling of the tree’s nodes proved hard as well. This is a little something I’ve been working on for a while: A replacement (or better: enhancement) of WPF’s built-in TreeView control. I’ll update the CodeProject article once the current filtering mechanism has been rewritten:ĭownload: wpf-treeview.zip (Current version: 1.0.7, updated 2008.04.06) Update: The latest version is currently only available through the download link below. And please leave your rating if you like the control □ A tutorial is now available on Code Project, so check the article for a detailed overview.