hierarchicaldatatemplate

How to reference a generic type in the DataType attribute of a HierarchicalDataTemplate?

只谈情不闲聊 提交于 2019-11-27 19:33:20
I have a class of MyClass<MyObject> and want to set it as the DataType for a HierarchicalDataTemplate. What is the syntax for this in XAML? (I know how to set namespaces, I need just the syntax for <HierarchicalDataTemplate DataType="{X:Type ..... Szymon Rozga itowlson's approach is a good one but it is just a start. Here's something that will work for your case (and most, if not all, cases): public class GenericType : MarkupExtension { public Type BaseType { get; set; } public Type[] InnerTypes { get; set; } public GenericType() { } public GenericType(Type baseType, params Type[] innerTypes)

How to get TreeViewItem from HierarchicalDataTemplate item?

。_饼干妹妹 提交于 2019-11-27 11:07:53
I have a TreeView which uses a HierarchicalDataTemplate to bind its data. It looks like this: <TreeView x:Name="mainTreeList" ItemsSource="{Binding MyCollection}> <TreeView.Resources> <HierarchicalDataTemplate DataType="{x:Type local:MyTreeViewItemViewModel}" ItemsSource="{Binding Children}"> <!-- code code code --> </HierarchicalDataTemplate> </TreeView.Resources> </TreeView> Now, from the code-behind of say the main window, I want to get the current selected TreeViewItem . However, if I use: this.mainTreeList.SelectedItem; The selectedItem is of type MyTreeViewItemViewModel . But I want to

How to reference a generic type in the DataType attribute of a HierarchicalDataTemplate?

南楼画角 提交于 2019-11-27 04:22:36
问题 I have a class of MyClass<MyObject> and want to set it as the DataType for a HierarchicalDataTemplate. What is the syntax for this in XAML? (I know how to set namespaces, I need just the syntax for <HierarchicalDataTemplate DataType="{X:Type ..... 回答1: itowlson's approach is a good one but it is just a start. Here's something that will work for your case (and most, if not all, cases): public class GenericType : MarkupExtension { public Type BaseType { get; set; } public Type[] InnerTypes {

How to group consecutive similar items of a collection?

ⅰ亾dé卋堺 提交于 2019-11-26 21:59:43
问题 Consider the following collection. True False False False True True False False I want to display it in a structured way, say, in a TreeView . I want to be able to draw borders around entire groups and such. True Group True False Group False False False True Group True True False Group False False How do I accomplish this with as little procedural code as possible? 回答1: This does what you're looking for and is generic: private static IEnumerable<IGrouping<int, T>> GroupConsecutive<T>(this

WPF Treeview Databinding Hierarchal Data with mixed types

柔情痞子 提交于 2019-11-26 17:25:08
I have a bit of a complex situation with WPF Treeview Binding. I have spent the last 2 days trying Google it, and this is the closed I came up with, but it doesn't solve the issue. Here is the situation: I have an object that looks like this: public class Category { public string Name { get; set; } public List<Category> Categories { get; set; } public List<Product> Products { get; set; } } public class Product { public string Name { get; set; } Each Category can have a list of objects, and child categories. I have a reason for doing this that makes complete sense to me, and the app I am

WPF TreeView HierarchicalDataTemplate - binding to object with multiple child collections

﹥>﹥吖頭↗ 提交于 2019-11-26 15:55:52
I am trying to get a TreeView to bind my collection so that all groups show nested groups and each group will show entry. How can I use the HierarchicalDataTemplate so that the TreeView will process both SubGroups and Entries collection? Groups show subgroups and entries: Example: Group1 --Entry --Entry Group2 --Group4 ----Group1 ------Entry ------Entry ----Entry ----Entry --Entry --Entry Group3 --Entry --Entry Objects: namespace TaskManager.Domain { public class Entry { public int Key { get; set; } public string Name { get; set; } } } namespace TaskManager.Domain { public class Group { public

WPF Treeview Databinding Hierarchal Data with mixed types

房东的猫 提交于 2019-11-26 05:25:11
问题 I have a bit of a complex situation with WPF Treeview Binding. I have spent the last 2 days trying Google it, and this is the closed I came up with, but it doesn\'t solve the issue. Here is the situation: I have an object that looks like this: public class Category { public string Name { get; set; } public List<Category> Categories { get; set; } public List<Product> Products { get; set; } } public class Product { public string Name { get; set; } Each Category can have a list of objects, and

WPF TreeView HierarchicalDataTemplate - binding to object with multiple child collections

牧云@^-^@ 提交于 2019-11-26 04:17:26
问题 I am trying to get a TreeView to bind my collection so that all groups show nested groups and each group will show entry. How can I use the HierarchicalDataTemplate so that the TreeView will process both SubGroups and Entries collection? Groups show subgroups and entries: Example: Group1 --Entry --Entry Group2 --Group4 ----Group1 ------Entry ------Entry ----Entry ----Entry --Entry --Entry Group3 --Entry --Entry Objects: namespace TaskManager.Domain { public class Entry { public int Key { get;