Added from comment .

<TreeView Height="500" Name="tvGroups" AllowDrop="True"> <DockPanel LastChildFill="True"> <TreeViewItem Name="parent1" DockPanel.Dock="Left" Header=">"> <TreeViewItem Header="A"> <TreeViewItem Header="Item 1"></TreeViewItem> <TreeViewItem Header="Item 2"></TreeViewItem> </TreeViewItem> <TreeViewItem Header="B"> <TreeViewItem Header="Item 1"></TreeViewItem> </TreeViewItem> </TreeViewItem> <Button DockPanel.Dock="Right" HorizontalAlignment="Left" VerticalAlignment="Top" Height="20" Content="Add"/> <Button DockPanel.Dock="Right" HorizontalAlignment="Left" VerticalAlignment="Top" Height="20" Content="Delete"/> </DockPanel> </TreeView> 
  • Do not forget to take the answers to the questions you ask. - AlexeyM pm
  • How to use? - Demon
  • To accept the answer that gave you, you need to click on the check mark from the answer (under the cam down). - Nicolas Chabanovsky

3 answers 3

In Matthew Macdonald's book WPF 4 C # is in some of the chapters about ListBox TreeViewItem, about creating buttons in a template, you simply attach each tag to the tag property, for example, the line number and when you click on the line X, you can continue to push something actions ....

    It is necessary to declare and connect the template for the TreeViewItem, which will be buttons.

    View:

     <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfApplication1" mc:Ignorable="d" Title="MainWindow" Height="350" Width="525"> <Window.DataContext> <local:ViewModel></local:ViewModel> </Window.DataContext> <Grid> <TreeView ItemsSource="{Binding MyItems}"> <TreeView.ItemTemplate> <HierarchicalDataTemplate ItemsSource="{Binding Children}"> <Button Foreground="Red" Content="{Binding Name}"></Button> </HierarchicalDataTemplate> </TreeView.ItemTemplate> </TreeView> </Grid> 

    ViewModel:

     public class ViewModel { public ObservableCollection<TreeItemViewModel> MyItems { get; set; } public ViewModel() { MyItems = new ObservableCollection<TreeItemViewModel>(); MyItems.Add(new TreeItemViewModel() { Name = "lvl1" }); MyItems.Add(new TreeItemViewModel() { Name = "lvl1", Children =new ObservableCollection<TreeItemViewModel>() {new TreeItemViewModel() { Name = "lvl2" } } }); MyItems.Add(new TreeItemViewModel() { Name = "lvl1" }); } } public class TreeItemViewModel { public ObservableCollection<TreeItemViewModel> Children { get; set; } public string Name { get; set; } } 

    Result:

    enter image description here