treeviewitem

Get parent TreeViewItem of a selected node in WPF

别说谁变了你拦得住时间么 提交于 2021-01-28 05:28:59
问题 I want the parent of a node that is selected as TreeViewItem I have a Person class with 2 fields. Name(String) and Children(List of string) This is my xaml code <Grid x:Name="gridView" Margin="10"> <TreeView Name="treeView1" TreeViewItem.Selected="TreeViewItem_OnItemSelected" ItemsSource="{Binding}"> <TreeView.ItemContainerStyle> <Style TargetType="{x:Type TreeViewItem}"> <Setter Property="IsSelected" Value="{Binding IsSelected, Source=Check, Mode=TwoWay}" /> </Style> </TreeView

Binding Errors in TreeViewItem (Horizontal and VerticalContentAlignment)

吃可爱长大的小学妹 提交于 2020-06-28 06:53:09
问题 I am getting these errors. I have read several posts and my TreeViewItem does have Horizontal and VerticalContentAlignment defined. Interestingly compiling in .NET 4.0+ makes the error go away (I use 3.5 - else I suffer from this https://connect.microsoft.com/VisualStudio/feedback/details/588343/changed-behaviour-from-net-3-5-to-net-4-0-of-wpf-textbox-formatting-when-proper) System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType

Get selected item in treview MVVM

元气小坏坏 提交于 2020-06-17 15:58:22
问题 I try to apply MVVM for treeview by refer to Josh's tutorial https://www.codeproject.com/Articles/26288/Simplifying-the-WPF-TreeView-by-Using-the-ViewMode Here is my full source code TreeNode.cs public class TreeNode { private ObservableCollection<TreeNode> _children = new ObservableCollection<TreeNode>(); public ObservableCollection<TreeNode> Children { get { return _children; } set { _children = value; } } public string Name { get; set; } public string ID { get; set; } } TreeNodeViewModel

Get selected item in treview MVVM

馋奶兔 提交于 2020-06-17 15:58:05
问题 I try to apply MVVM for treeview by refer to Josh's tutorial https://www.codeproject.com/Articles/26288/Simplifying-the-WPF-TreeView-by-Using-the-ViewMode Here is my full source code TreeNode.cs public class TreeNode { private ObservableCollection<TreeNode> _children = new ObservableCollection<TreeNode>(); public ObservableCollection<TreeNode> Children { get { return _children; } set { _children = value; } } public string Name { get; set; } public string ID { get; set; } } TreeNodeViewModel

Activate command on TreeViewItem click, VSCode Extension

不羁岁月 提交于 2020-03-21 19:26:16
问题 I would like to run a command on the click of a tree view item, rather than in a menu that comes up. Right now in my package.json, I have this: { "command": "test.view.showError", "when": "view == test.view && viewItem == test", "group": "inline" } Right now, "inline" will put an icon next to the words which you have to click to run the command, but I would like the command to run when I click on the node itself. What do I change "group" to? Or do I do something different entirely? Thanks 回答1

Custom WPF TreeViewItem style is behaving incorrectly when databound

谁都会走 提交于 2020-01-26 00:29:10
问题 I have adapted a TreeViewItemStyle to my need and it works great when I have hardcoded my TreeViewItems like so: <TreeView Grid.Column="0" HorizontalAlignment="Stretch" Name="treeView1" VerticalAlignment="Stretch" > <TreeView.Items> <TreeViewItem Header="McDonalds" IsExpanded="True"> <TreeViewItem.Items> <TreeViewItem Header="Burger" IsExpanded="True" IsSelected="True"> <TreeViewItem.Items> <TreeViewItem Header="Meat" /> </TreeViewItem.Items> </TreeViewItem> </TreeViewItem.Items> <

How to highlight entire row in WPF TreeView

三世轮回 提交于 2020-01-23 01:28:07
问题 I want to adapt the default WPF TreeView/TreeViewItem template, so that the entire row can be highlighted, as shown in the image: However, I've tried several templates from googling, but none of them can really make the effects, some wrong answers were even marked as correct... There was an answer in codeflow which seems to work, but it add extra C# code, or didn't need extra code but not working perfectly. I don't want to add extra C# code, but only change the default template. Anyone have

WPF treeview item background over entire row

五迷三道 提交于 2020-01-19 14:15:48
问题 i am writing one app and i need to set background under entire row by items. I found some inspiration in here but i cannot get idea how to get Border background value in template (the problem is a bit more complicated:) My problem is that in the treeview are 2 types of "data" (files and folders). User can modify the background under files and folders. Right now i have the background on textblock, but it seems horrible and i want to have the background over entire row (i think it will looks

How to add to a TreeView directory at runtime

断了今生、忘了曾经 提交于 2020-01-11 12:57:11
问题 I have a TreeView in which I would like to allow the user to add and delete subitems from. In exploring basic functionality I am using a button and a textbox to add this subitem. When the user clicks on the button a new TreeViewItem needs to be created and set as a subitem of my parent TreeView with the text from the textbox set as the subitem's Header . This is my current code under the button_click event: //ADD T_ITEM TO PARENT TREEVIEW private void button1_Click(object sender,