// TODO: into behavior?
        protected override void OnPreviewMouseRightButtonDown(MouseButtonEventArgs e)
        {
            NodeForContextMenu = null;

            NodeItem nodeItem = null;

            if (Keyboard.Modifiers == ModifierKeys.Control)
            {
                // in case the full treeview is filled with nodes there is no option to
                // open context menu without selecting any node (because nodes stretch horizontally)
                // -> use a modifier to signal that context menu should be opened with the full tree as context
                nodeItem = null;
            }
            else
            {
                nodeItem = ((DependencyObject)e.OriginalSource).FindParentOfType <NodeItem>();
            }

            if (nodeItem != null)
            {
                NodeForContextMenu = (INode)nodeItem.DataContext;

                nodeItem.Focus();
            }
            else
            {
                // if we click directly into the tree control we pick Root
                NodeForContextMenu = StateContainer.DataContext;
            }

            RefreshContextMenuCommandsCanExecute();

            e.Handled = true;
        }
Exemplo n.º 2
0
        public void Attach(NodeItem nodeItem)
        {
            myAttachedView = nodeItem;

            myAttachedView.IsFilteredOut = IsFilteredOut;

            var expr = myAttachedView.GetBindingExpression(TreeViewItem.IsExpandedProperty);

            if (expr != null)
            {
                // property bound to INode impl --> this is the master
                IsExpanded = myAttachedView.IsExpanded;
            }
            else
            {
                // no binding --> we are the master
                myAttachedView.IsExpanded = IsExpanded;
            }
        }