hierarchicaldatatemplate

How to bind to the DataContext of a HierarchicalDataTemplate from its ItemTemplate XAML?

故事扮演 提交于 2019-12-02 07:20:32
问题 In my WPF TreeView, I have defined a HierarchicalDataTemplate . In its ItemTemplate , there is a button whose Command I need to bind to the parent ViewModel, this is the DataContext of the parent HierarchicalDataTemplate or, in other words, the ViewModel which holds the collection SubItems in the example below. The ItemTemplate s own DataContext - the SubItem - is to be used as the CommandParameter . <TreeView ItemsSource="{Binding Items}"> <TreeView.ItemTemplate> <HierarchicalDataTemplate

WPF Menu - How to use a different template for top-level items

◇◆丶佛笑我妖孽 提交于 2019-12-02 03:54:41
问题 I would like to apply different templates to my WPF menu control depending on whether the item is a "top level" item or not. In particular, I want a larger icon above the text for top-level items and a smaller icon to the left of the text for the other items. This is the (working) XAML I'm using now, which correctly formats the top-level items but leaves the other items looking silly and too-large: <WrapPanel Height="Auto"> <Menu ItemsSource="{Binding DataContext.EventMenu.TopLevel,

How to bind to the DataContext of a HierarchicalDataTemplate from its ItemTemplate XAML?

你。 提交于 2019-12-02 00:02:37
In my WPF TreeView, I have defined a HierarchicalDataTemplate . In its ItemTemplate , there is a button whose Command I need to bind to the parent ViewModel, this is the DataContext of the parent HierarchicalDataTemplate or, in other words, the ViewModel which holds the collection SubItems in the example below. The ItemTemplate s own DataContext - the SubItem - is to be used as the CommandParameter . <TreeView ItemsSource="{Binding Items}"> <TreeView.ItemTemplate> <HierarchicalDataTemplate ItemsSource="{Binding SubItems}"> <HierarchicalDataTemplate.ItemTemplate> <DataTemplate> <Button Command=

WPF TreeView HierarchicalDataTemplate - binding to object with different child collections

旧街凉风 提交于 2019-12-01 08:00:18
I am trying to bind a collection to wpf TreeView control using data templates. Each item(Person) in the collection also contains two different collections(Cars, Books) of type car and book. Here's simplified list of the objects involved to save space. public class Person { public string Name public List<Book> Books; public List<Car> Cars; } public class Book { public string Title public string Author } public class Car { public string Manufacturer; public string Model; } Here is how I am binding public MainWindow() { InitializeComponent(); this.treeView1.ItemsSource = this.PersonList(); }

WPF Binding parent property in HierarchicalDataTemplate

前提是你 提交于 2019-11-29 11:02:04
I have a WPF TreeView with 2 levels of data and 2 HierarchicalDataTemplate to format each level. From the HierarchicalDataTemplate at the second level, I need to bind a property in the class of the first level. I have tried in this way, but it dosn't work: Text="{Binding Path=Ori, RelativeSource={RelativeSource TemplatedParent}}" with Ori as the name of the propery Even in this way it dosn't works: Text="{Binding Path=tOri, RelativeSource={RelativeSource TemplatedParent}}" with tOri as the name of the TextBlock in the fisrt HierarchicalDataTemplate that bind the Ori propery. Can you help me?

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

倾然丶 夕夏残阳落幕 提交于 2019-11-28 07:51:54
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] <----- Object of ModelClass B1 (have children of different type as well) ----[ChildNode B2] <----- Object of

Binding SelectedItem in a HierarchicalDataTemplate-applied WPF TreeView

不羁的心 提交于 2019-11-28 06:58:56
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.SetValue(TreeViewItem.IsSelectedProperty, true); } } This is my TreeView definition: <Window xmlns

WPF Binding parent property in HierarchicalDataTemplate

一个人想着一个人 提交于 2019-11-28 04:24:32
问题 I have a WPF TreeView with 2 levels of data and 2 HierarchicalDataTemplate to format each level. From the HierarchicalDataTemplate at the second level, I need to bind a property in the class of the first level. I have tried in this way, but it dosn't work: Text="{Binding Path=Ori, RelativeSource={RelativeSource TemplatedParent}}" with Ori as the name of the propery Even in this way it dosn't works: Text="{Binding Path=tOri, RelativeSource={RelativeSource TemplatedParent}}" with tOri as the

Grouping child objects in WPF TreeView

前提是你 提交于 2019-11-28 03:44:57
问题 I am trying to get my tree view to group a collection of similar items by what they are. To keep things generic, my object hierarchy could look like this: Objects Object Group #1 Item #1 (Type 'A') Item #2 (Type 'A') Item #3 (Type 'B') Item #4 (Type 'B') Right now my TreeView shows these objects exactly like the object model, but what I would like to do is insert a TreeView node for each object type so that it would look like this: Objects Object Group #1 Type A Item #1 Item #2 Type B Item #3

How to group consecutive similar items of a collection?

有些话、适合烂在心里 提交于 2019-11-28 01:38:04
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? This does what you're looking for and is generic: private static IEnumerable<IGrouping<int, T>> GroupConsecutive<T>(this IEnumerable<T> set, Func<T, T, bool> predicate) { var i = 0; var k = 0; var ranges = from e in set let idx = +