treeviewitem

Changing the itemsSource of a treeview makes it's children invisible, when they were already displayed

I found some strange problem in WPF, using the itemsSource of a treeview. I hope I can make this specific problem clear for you. First; a story. There is a treeview. It has a list with treeviewitems as itemsSource. This list is called _roots. There is another list, called _leafs. For as in a treeview, the _roots contain the _leafs in so...

KeyBinding on a TreeViewItem

I have a typical treeview and a viewmodel. The viewmodel has an observable collection of other viewmodels that serves as a data source for the tree. public class TreeViewVM { public ObservableCollection<ItemVM> Items { get; private set; } public ItemVM SelectedItem { get; set; } } and the ItemVM : public class ItemVM { ...

How do you get the level of a treeviewitem in WPF C#?

How do you get the level of a treeviewitem in WPF C#? In windows forms there is a .Level member of the treeview class but there does not seem to be one for WPF C#. ...

How do I perform hit test in TreeView for TreeViewItem?

I have a System.Windows.Controls.TreeView in my project, and when the user right click in it, I'm displaying a context menu. Since the context menu is built dynamically, I need to know the System.Windows.Controls.TreeViewItem that the mouse is hovering over. How do I do this? ...

how to get the available (visible) width of the TreeViewItem inside a TreeView

Hi, I have TreeViewItems where the HierarchicalDataTemplate consists of a Grid with 3 columns with the following definitions: <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="1*" /> <ColumnDefinition Width="Auto" /> ... I want to set the width of the grid so that it would ta...

WPF refresh TreeView when it loses the focus

Hi! 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...

WPF: Getting TreeViewItem's constituent controls

Hi, 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="I...

Getting the TreeViewItem on newly created items

There has to be a better way then the following for getting "childItem" TaskItem task = (sender as Canvas).DataContext as TaskItem; TaskItem child = Tasks.CreateTask("New task", task); TreeViewItem item = treeView.ItemContainerGenerator.ContainerFromItem(task) as TreeViewItem; item.UpdateLayout(); TreeVi...

Expand just the root node of tree in XAML

Hello out there, is there any way to expand just the root node of a WPF tree in XAML? Thanks! Dirk ...

WPF - Setting different ToggleButton image for each TreeViewItem root node with styles

I am new to using styles, resources and templates in WPF. What I need to do is override the ToggleButton +/- in the TreeView to be an image, with a different image for each TreeViewItem root Node. For Instance, I would want an image of a car for the "Car" node, and an image of an airplane for the "Plane" node. I have a colorful and a ...

Handled RoutedEvent continues to bubble up tree

Hello: I'm developing a TreeView based control and my double click event continues to bubble up my TreeViewItem nodes. The goal is to have the TreeViewItem expand or collapse when it is double clicked. I have a style that applies an event handler for the MouseDoubleClick event to each TreeViewItem. Here's the code that handles the e...

Is there a way to bind a command to the collapsed event of all TreeViewItems in a treeview?

I am trying to do something similar to what the person in this question wanted to do. Is there any, more elegant, way to do this than the work-around suggested there? (As a last resort) Is there a different mvvm framework that would have better support for doing this? Right now I'm trying to make a custom control that inherits from t...

Wpf- How can I get the TreeViewItem that triggered the TreeViewItem.Loaded event?

I am trying to attach some handlers to each TreeViewItem as they are loaded and then remove the handlers as they are unloaded. Here is the Code that I have in my custom control which inherits from TreeView: public ModdedTreeView() { this.AddHandler(TreeViewItem.LoadedEvent, new RoutedEventHandler(ItemLoaded)); ...

TreeviewItem disappears after draggin it onto a grid

I am dragging and dropping a Treeviewitem from a RadTreeview in my WPF/C# project. After a succesful drag and drop the node disappears from the treeview. How can I avoid this? which event handler to change for this? I am assuming that this should be done in teh treeview's drag event handler and nothing to do with the grid's drop event ha...

Modify or 'tweak' an existing TreeViewItem control template?

Ok... this is sort of a two-parter here. (Sort of. May actually just be one. That's what I'm hoping anyway.) First, more generally, is it possible to target, via XAML only, a named item in a control's template? For instance, if a control's template has a ContentPresenter named 'PART_Foo' and we want to specifically set the Horizonta...

Modify or 'tweak' an existing TreeViewItem control template - Take II

Ok, this is sort of a follow-up to my first question http://stackoverflow.com/questions/3827701/modify-or-tweak-an-existing-treeviewitem-control-template but since it is technically a new question, I'm told a good S/O visitor should create a new one, so here it is! Ok... the existing template for a TreeViewItem is based on a grid, a bor...

How to apply a global style (allowing hightlighting after focus is lost) to a wpf treeview

I found the following code for showing the selected item in a treeview when focus has left, but I'm having trouble moving the code to App.xaml so any UserControl could use it. This does what I want <TreeView x:Name="trviewArchives" Width="141" Height="154" Canvas.Left="20" Canvas.Top="167" Background="{x:Null}" BorderBrush="#FF08182...

Focusing WPF TreeViewItem when selection changes in another control

Hi All, In my WPF application I have a treeview which is loaded with certain collection. At the top of this tree view control i have a listbox which stores the same items as in the tree view whenever the tree view items are made favorites. I am trying to focus the treeview item whenever there is a selection made in the listbox. Though t...

WPF TreeViewItem Header Value After DataBinding

Hi, I have a TreeView whose contents (nested TreeViewItems) are generated from a dataset via databinding, which all seems to work fine. The issue I'm running into is that when I try and manipulate the contents of the TreeViewItem headers in code, the Header property returns the DataRowView that the TreeViewItem was generated from and no...