hierarchicaldatatemplate

Implement WPF treeview with different Parent Nodes a well as different child nodes?

守給你的承諾、 提交于 2019-12-17 18:30:45
问题 I want to implememt a tree view with has the following structure..... [RootNode] <---- Root of tree --[ParentNode P1] <---- Object of ModelClass P1 ----[ChildNode C1] <----- Object of ModelClass C1 (have children of different type as well) ----[ChildNode C2] <----- Object of ModelClass C2 (have children of different type as well) ----[ChildNode C3] <----- Object of ModelClass C3 (have children of different type as well) --[ParentNode Q1] <---- Object of ModelClass Q1 ----[ChildNode B1] <-----

Binding SelectedItem in a HierarchicalDataTemplate-applied WPF TreeView

无人久伴 提交于 2019-12-17 18:20:03
问题 I have a data-bound TreeView and I want to bind SelectedItem . This attached behavior works perfectly without HierarchicalDataTemplate but with it the attached behavior only works one way (UI to data) not the other because now e.NewValue is MyViewModel not TreeViewItem . This is a code snippet from the attached behavior: private static void OnSelectedItemChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { var item = e.NewValue as TreeViewItem; if (item != null) { item

TreeView, HierarchicalDataTemplate and recursive Data

喜欢而已 提交于 2019-12-17 10:54:26
问题 For my treeview I have two different classes that provide the ItemsSource. public class TreeViewModel : ViewModelBase { public ObservableCollection<NodeViewModel> Items { get; set; } } public class NodeViewModel : ViewModelBase { public string Id { get; set; } public string Name { get; set; } public ObservableCollection<NodeViewModel> Children { get; set; } } Now I want my TreeView to display the Items in TreeViewModel and show hierarchical data as provided by the NodeViewModel. Here is my

How to get TreeViewItem from HierarchicalDataTemplate item?

爷,独闯天下 提交于 2019-12-17 10:22:58
问题 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

HierarchicalDataTemplate and Many-To-Many with Payload Entities Navigation Binding Issue

独自空忆成欢 提交于 2019-12-13 19:43:20
问题 I have two Many-To-Many with Payload entities as shown below: So, to make an Assembly stored in MasterPartNumber with a part number: MasterPartNumber.pn , I use the navigation property ParentBOMs , which is given by the relationship: MasterPartNumber.pnID = MasterPartsList.parentPnID . This gives me all the child pnIDs under that parent assembly. To get the child part numbers for that assembly , I use the ChildPn navigation property, defined by MasterPartsList.pnID = MasterPartNumber.pnID .

HierarchicalDataTemplate not working

[亡魂溺海] 提交于 2019-12-12 10:25:45
问题 I am trying to use a HierarchicalDataTemplate to recursively create expanders with items in them but when I use the HierarchicalDataTemplate I only get the first level of items displayed. Please let me know if you need anyore information. Heres the what the xaml would look like if I was writing by hand: <GroupBox Header="SectionHeader"> <StackPanel > <Expander VerticalAlignment="Top" Header="SubSectionHeader"> <StackPanel> <Expander VerticalAlignment="Top" Header="SubSectionHeader" Margin="10

WPF model-bound menu with different ItemContainerStyle at top level and other levels

我怕爱的太早我们不能终老 提交于 2019-12-12 02:06:32
问题 I am attempting to construct a dynamic WPF menu with different appearance for the top level items and the subsequent level items. In particular, I would like my top level items to display a 32 pixel square image on top of the menu caption, and the subsequent items to display a 16 pixel image in the regular Icon location. (I posted a related question some days ago, that one was using templates instead of styles). The XAML code below produces a menu with the following characteristics: . All

Binding hierarchical treeview from database

廉价感情. 提交于 2019-12-11 13:36:49
问题 I am totally new to using TreeView. My solution has two projects one called the Business Layer i.e a class library that gets data from the database and the other actual WPF application itself. I have two very simple tables in my Family database that have data as follows: I have four classes in my Business Layer project. 1) ChildrenModel.cs public class ChildrenModel { public string Name { get; set; } public int Age { get; set; } public double Income { get; set; } public string Address { get;

Adding Custom Class as TreeViewItem to TreeView WPF

瘦欲@ 提交于 2019-12-11 07:31:43
问题 I have scenario where my TreeView look like below: MainParent .>-Parent ...>--Child1 ...>--Child2 ...>--Child3 ...>--Child4 ...>--Child5 ......> Child1_Of_Child5 ...........>Child1(Child1_Of_Child5) ...........>Child2(Child1_Of_Child5) ......> Child2_of_Child5 ...........>Child1(Child2_Of_Child5) ...........>Child2(Child2_Of_Child5) I am able to bind ObservableCollection till Child1/Child2/../Child5 using HierarchicalDataTemplate. Though I am able to add Child1_Of_Child5 to Child5

Both 'ItemTemplate' and 'ItemTemplateSelector' are set; 'ItemTemplateSelector' will be ignored

别来无恙 提交于 2019-12-11 07:16:07
问题 Following this question, I have another question about TreeView . What I already have is a TreeView with HierarchicalDataTemplate , in which I can change the HierarchicalDataTemplate of level2 (like explained in the question and the answer). What I want now, is to change the look of the expander of the Treeview . For this, I have defined a ControlTemplate named ctForTreeViewItem , and I use it like this: <Window.Resources> <ControlTemplate x:Key="ctForTreeViewItem" TargetType="{x:Type