treeviewitem

TreeViewItem.Header with Grid inside

大憨熊 提交于 2020-01-04 05:42:51
问题 I'm trying to make "Img" appear in the end of TreeViewItem.Header (as close to the right side of TreeView control), but no mater what I try header wide is always less than TreeView size and ofcourse "Img" appear somewhere in the middle of the control. This probably a very newbish question; I'm just starting to learn WPF. <TreeView Grid.Row="1" Grid.ColumnSpan="2" Margin="3,3,3,3" Name="treeView1" Width="300"> <TreeViewItem HorizontalAlignment="Stretch"> <TreeViewItem.Header> <Grid

TreeViewItem With Stretch

天涯浪子 提交于 2019-12-29 09:05:25
问题 I want to create a WPF TreeView that contains TreeViewItems that stretch to fill the available space. I modified the TreeViewItem template using this as a guide: https://social.msdn.microsoft.com/Forums/vstudio/en-US/cabcb3ba-80c0-4367-85b7-9b55adc81e65/stretch-treeview-items?forum=wpf and this works well as I want the one character grid components on the right hand side to be right aligned and for the long TextBlock to take up the available space - see code below where the header for one of

WPF: Getting TreeViewItem's constituent controls

拜拜、爱过 提交于 2019-12-25 16:42:28
问题 how can I get the constituent controls making up the TreeViewItem in code if they are inside a hierarichicaldatatemplate? <HierarchicalDataTemplate DataType="{x:Type local:Module}" ItemsSource="{Binding Children}"> <StackPanel Orientation="Horizontal"> <Image Width="16" Height="16" Margin="3,0" Source="Images\module.ico" /> <local:RenamingNode Name="RenamableNode" Text="{Binding Name}" VstaObject="{Binding BindsDirectlyToSource=True}" OnRename="OnRenameOccured" /> </StackPanel> <

WPF refresh TreeView when it loses the focus

别说谁变了你拦得住时间么 提交于 2019-12-25 04:56:18
问题 I have a problem with my TreeView in a WPF application (Framework 3.5 SP1). It's a TreeVIew with 2 Levels of Data. I expand / collapse the items of the first level in a particular way (with a single mouse-click on the TreeViewItem). Again when I expand a first-level TreeViewItem, I add some second-level TreeViewItems to the group (it's an important detail, infact if I don't add the items the problem doesn't occur). All works good until the TreeView loses focus. If, for example, I expand the

How can I specify which TreeViewItem Style/Template for a TreeViewItem Generated from HierarchicalDataTemplate?

我只是一个虾纸丫 提交于 2019-12-25 04:47:17
问题 The Situation: I have two classes that are represented in a TreeView. DiskSpec and DiskSet. DiskSpec can exist by itself, or it can be a child of DiskSet. I am working on enabling DragDrop functionality so that the user can drag a DiskSpec from the DiskSpec node onto a DiskSet to add it to that DiskSet. Now all is working except for one thing. My DragDropHelper class needs to specify in an ItemsPresenter (or related class) that that control is a drag source or a drop target. My TreeView is

Get TreeViewItem for TreeView logical element

老子叫甜甜 提交于 2019-12-25 02:28:09
问题 My tree view seems like this <TreeView x:Name="ArticlesTreeView" Grid.Column="0" AllowDrop="True"> <TreeView.Resources> <HierarchicalDataTemplate DataType="{x:Type structure:NewsPaperDocument}" ItemsSource="{Binding Children}"> <TextBlock Text="{Binding Name}" Tag="{Binding Object}" FontWeight="Bold" /> </HierarchicalDataTemplate> <HierarchicalDataTemplate DataType="{x:Type structure:NewsPaperPage}" ItemsSource="{Binding Children}"> <TextBlock Text="{Binding Name}" Tag="{Binding Object}"

How I can get content of TreeViewItem in WPF?

ⅰ亾dé卋堺 提交于 2019-12-24 15:33:46
问题 For example, my TreeViewItem' header consists of TextBlock and Image. How I can get references to them? 回答1: I'm not sure if I got you right, but if you want to get visual children of an element, try using VisualTreeHelper.GetChild and VisualTreeHelper.GetChildrenCount . PS: usually it's more problematic to get a reference to the TreeViewItem itself... UPDATE (A code example for future generations): private IEnumerable<DependencyObject> GetChildren(DependencyObject parent) { var count =

TreeView fontsize - Custom Draw or Owner Draw

廉价感情. 提交于 2019-12-24 12:55:13
问题 I want to change the font size of a TreeView control. After searching on goolge, I just get some idea that one should use CustomDraw for this TreeView. But NMTVCUSTOMDRAW structure only has clrText and clrText which set the foreground and background color of the displayed texts in TreeView. My questions are: Q1: How to change the font size in a TreeView? For the background color of TreeView, one can just use `TreeView_SetBkColor` or send a message. Anything similar for font size? Q2: What's

How do you determine the width of the text in a WPF TreeViewItem at run time?

若如初见. 提交于 2019-12-24 07:51:14
问题 How do you determine the width of the text in a WPF TreeViewItem at run time? I need to calculate an offset so I can draw a line from one leaf to the leaf of a different TreeView. All the 'width' properties return a size that is way bigger than the space taken up by the actual text of the node. It must be possible because the Select feature doesn't highlight the entire row. I'm writing the client in WPF and Silverlight. 回答1: You weren't very specific on the text or the tags, so I'm assuming

Why do items in TreeViewItem inherit the event handlers of parent?

眉间皱痕 提交于 2019-12-24 01:18:31
问题 So, I create a TreeViewItem (parentNode), and I add TreeViewItems into the parentNode TreeViewItem. I then add a MouseButtonEventHandler to the parentNode, and now all the TreeViewItems inside parentNode have the MouseButtonEventHandler. I've run the debugger to see if I have code that was accidentally written to add the MouseButtonHandler, but there isn't... Edit: I did additional tests, and it even goes two levels down. Is there a way to isolate eventhandlers to only the specific node and