This project is read-only.

TreeView inside DockableContent, right-click problems

Jun 1, 2010 at 4:50 PM

Hi there,

I have a TreeView with some nodes populated vis HierarchicalDataTemplate. It works fine in a simple XAML window.

The moment I place the TreeView inside a DocableContent, the right click starts misbehaving. I have a root node and a couple of child nodes under it. For some reason, right-clicking on any of the children automatically selects the parent, instead of the child. Perhaps AvalonDock is handling the right-click events in a different way.

I'm using 2.0 since I'm under .NET 3.5

Here's the code:

<Window x:Class="WpfApplication1.TreeViewTest"
    Title="TreeViewTest" Height="300" Width="300">

            <ad:ResizingPanel Orientation="Horizontal">
                <ad:DockablePane ad:ResizingPanel.ResizeWidth="150">
                    <ad:DockableContent Title="Presets">

                        <TreeView FocusManager.IsFocusScope="True">
            <TreeViewItem Header="Hello" />
            <TreeViewItem Header="All People" ItemsSource="{Binding People}"
                    <HierarchicalDataTemplate ItemsSource="{Binding Subordinates}">
                        <TextBlock Text="{Binding Name}"/>

                <ad:DocumentPane x:Name="paneGridViews">
                        Hello world


The codebehind is as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.ComponentModel;
using WpfApplication1.DataModel;
using System.Collections.ObjectModel;

namespace WpfApplication1
    /// <summary>
    /// Interaction logic for TreeViewTest.xaml
    /// </summary>
    public partial class TreeViewTest : Window
        public TreeViewTest()
            People = new ObservableCollection<Person>();
            People.Add(new Person() { Name = "Person1" });
            People.Add(new Person() { Name = "Person2" });
            People.Add(new Person() { Name = "Person3" });
            People[0].Subordinates.Add(new Person() { Name = "Person4" });
            People[0].Subordinates.Add(new Person() { Name = "Person5" });
            People[1].Subordinates.Add(new Person() { Name = "Person6" });
            People[1].Subordinates.Add(new Person() { Name = "Person7" });

            DataContext = this;

        public ObservableCollection<Person> People
            get { return (ObservableCollection<Person>)GetValue(PeopleProperty); }
            set { SetValue(PeopleProperty, value); }

        public static readonly DependencyProperty PeopleProperty =
            DependencyProperty.Register("People", typeof(ObservableCollection<Person>), typeof(TreeViewTest), new UIPropertyMetadata(null));

    public class Person : INotifyPropertyChanged
        private string _name;

        public string Name
            get { return _name; }
                if (_name != value)
                    _name = value;

        private ObservableCollection<Person> _subordinates;
        public ObservableCollection<Person> Subordinates
                if (_subordinates == null)
                    _subordinates = new ObservableCollection<Person>();
                return _subordinates;

        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName)
            var handler = PropertyChanged;
            if (handler != null)
                handler(this, new PropertyChangedEventArgs(propertyName));

Jun 3, 2010 at 10:13 AM


Thanks for the feedback, this issue is now corrected (version 1.3.3398). The problem is due to a wrong focus setting of the dockablecontent.

You have two choices:

- Edit AD code commenting out line 'ContainerPane.Focus()' in the DockableContent.SetAsActive()
- Handle the mousedown event of the listbox and set the flag e.Handled to true, in this case mouse event is not escalated to DockableContent.

Hope this can help!