Beispiel #1
0
        void hexBox_ContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            bool            openedFromKeyboard = e.CursorLeft == -1 && e.CursorTop == -1;
            TextViewContext context            = TextViewContext.Create(hexBox: hexBox, openedFromKeyboard: openedFromKeyboard);
            ContextMenu     menu;

            if (ShowContextMenu(context, out menu))
            {
                var rect = hexBox.GetCaretWindowRect();
                if (rect != null && openedFromKeyboard)
                {
                    var pos = rect.Value.BottomLeft;
                    menu.HorizontalOffset = pos.X;
                    menu.VerticalOffset   = pos.Y;
                    ContextMenuService.SetPlacement(hexBox, PlacementMode.Relative);
                    ContextMenuService.SetPlacementTarget(hexBox, hexBox);
                    menu.Closed += (s, e2) => {
                        hexBox.ClearValue(ContextMenuService.PlacementProperty);
                        hexBox.ClearValue(ContextMenuService.PlacementTargetProperty);
                    };
                }
                else
                {
                    hexBox.ClearValue(ContextMenuService.PlacementProperty);
                    hexBox.ClearValue(ContextMenuService.PlacementTargetProperty);
                }
                hexBox.ContextMenu = menu;
            }
            else
            {
                // hide the context menu.
                e.Handled = true;
            }
        }
        void listBox_ContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            TextViewContext context = TextViewContext.Create(listBox: listBox);
            ContextMenu     menu;

            if (ShowContextMenu(context, out menu))
            {
                listBox.ContextMenu = menu;
            }
            else
            {
                // hide the context menu.
                e.Handled = true;
            }
        }
        void textView_ContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            TextViewContext context = TextViewContext.Create(textView: textView);
            ContextMenu     menu;

            if (ShowContextMenu(context, out menu))
            {
                textView.ContextMenu = menu;
            }
            else
            {
                // hide the context menu.
                e.Handled = true;
            }
        }
        void listBox_ContextMenuOpening(object sender, CancelEventArgs e)
        {
            TextViewContext context = TextViewContext.Create(listBox: listBox);
            ContextMenu     menu    = (ContextMenu)sender;

            if (ShowContextMenu(context, out IEnumerable <IControl> items))
            {
                menu.Items = items;
            }
            else
            {
                // hide the context menu.
                e.Cancel = true;
            }
        }
Beispiel #5
0
        void dataGrid_ContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            TextViewContext context = TextViewContext.Create(dataGrid: dataGrid);
            ContextMenu     menu;

            if (ShowContextMenu(context, out menu))
            {
                dataGrid.ContextMenu = menu;
            }
            else
            {
                // hide the context menu.
                e.Handled = true;
            }
        }
        void treeView_ContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            TextViewContext context = TextViewContext.Create(treeView);

            if (context.SelectedTreeNodes.Length == 0)
            {
                e.Handled = true;                 // don't show the menu
                return;
            }
            ContextMenu menu;

            if (ShowContextMenu(context, out menu))
            {
                treeView.ContextMenu = menu;
            }
            else
            {
                // hide the context menu.
                e.Handled = true;
            }
        }
        void treeView_ContextMenuOpening(object sender, CancelEventArgs e)
        {
            TextViewContext context = TextViewContext.Create(treeView);

            if (context.SelectedTreeNodes.Length == 0)
            {
                e.Cancel = true; // don't show the menu
                return;
            }
            ContextMenu menu = (ContextMenu)sender;

            if (ShowContextMenu(context, out IEnumerable <IControl> items))
            {
                menu.Items = items;
            }
            else
            {
                // hide the context menu.
                e.Cancel = true;
            }
        }
Beispiel #8
0
        void textView_ContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            bool            openedFromKeyboard = e.CursorLeft == -1 && e.CursorTop == -1;
            TextViewContext context            = TextViewContext.Create(textView: textView, openedFromKeyboard: openedFromKeyboard);
            ContextMenu     menu;

            if (ShowContextMenu(context, out menu))
            {
                if (openedFromKeyboard)
                {
                    var scrollInfo = (System.Windows.Controls.Primitives.IScrollInfo)textView.TextEditor.TextArea.TextView;
                    var pos        = textView.TextEditor.TextArea.TextView.GetVisualPosition(textView.TextEditor.TextArea.Caret.Position, ICSharpCode.AvalonEdit.Rendering.VisualYPosition.TextBottom);
                    pos = new Point(pos.X - scrollInfo.HorizontalOffset, pos.Y - scrollInfo.VerticalOffset);

                    menu.HorizontalOffset = pos.X;
                    menu.VerticalOffset   = pos.Y;
                    ContextMenuService.SetPlacement(textView, System.Windows.Controls.Primitives.PlacementMode.Relative);
                    ContextMenuService.SetPlacementTarget(textView, textView.TextEditor.TextArea.TextView);
                    menu.Closed += (s, e2) => {
                        textView.ClearValue(ContextMenuService.PlacementProperty);
                        textView.ClearValue(ContextMenuService.PlacementTargetProperty);
                    };
                }
                else
                {
                    textView.ClearValue(ContextMenuService.PlacementProperty);
                    textView.ClearValue(ContextMenuService.PlacementTargetProperty);
                }
                textView.ContextMenu = menu;
            }
            else
            {
                // hide the context menu.
                e.Handled = true;
            }
        }