![]() ![]() If you want to bind heterogeneous data to the tree, chances are high that your bound items do have something in common, and having them implement a common interface or derive from a custom base class might be a good design decision anyway. What if I want to bind items of various types to the tree? Otherwise, Intellisense in Visual Studio might not work properly. Hint: Make sure your tree control class is public. ![]() 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 GetChildItems(ShopCategory parent) the sample uses the category's name as the identifier public override string GetItemKey(ShopCategory item) a tree control that handles ShopCategory objects public class CategoryTree : TreeViewBase As you can see, CategoryTree manages with 3 lines of code: Below is the implementation of the sample project's CategoryTree control, which operates upon ShopCategory objects. There are quite a few virtual methods you can override in order to control the tree's behavior, but these three abstract methods may well be everything you'll ever need. How to get a bound item's parent, if there is one: GetParentItem.How to get a bound item's childs, if there are any available: GetChildItems.How to generate a unique identifier for a given tree node: GetItemKey.However, chances are high that you'll stay below 10 lines of code, as the base class just needs to know three things: That's abstract like in: You will have to write some code (gasp!) in order to getting started. Extending TreeViewBaseĪll the features of V-Tree are being provided by the abstract TreeViewBase class. As I'll refer to WPF's built-in TreeView control a lot, I'll call it V-Tree throughout this article (which is completely random, btw). However, I won't write that all over the place because that just sounds horribly narcistic, and it doesn't really make sense here at CP anyway. Regarding terms: Actually, this is the " WPF TreeView Control," as I published the initial version on my blog. If you're already tired of reading, you might just download the sample, play around, and come back later if you need more information. Pretty much everything I am going to write here is illustrated in the sample application that comes with the download. The tree layout (expanded/selected nodes) can be saved and reapplied. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |