Пример #1
0
        private void OnContextMenuButtonClick(object sender, ContextMenuButtonEventArgs e)
        {
            var moreCommand = MoreCommand;

            if (moreCommand != null)
            {
                MoreCommand?.Execute(null);
                e.Handled = true;
            }
        }
Пример #2
0
        private bool Open(bool near)
        {
            var args = new ContextMenuButtonEventArgs();

            Click?.Invoke(this, args);
            if (args.Handled)
            {
                return(true);
            }

            var menu = args.Menu ?? Menu;

            var popup = menu as Popup;

            if (popup != null)
            {
                if (popup.IsOpen)
                {
                    popup.IsOpen = false;
                }
                else
                {
                    popup.Placement       = near ? PlacementMode.Bottom : PlacementMode.MousePoint;
                    popup.PlacementTarget = near ? this : null;
                    popup.IsOpen          = true;
                    popup.StaysOpen       = false;
                }
                return(true);
            }

            var contextMenu = menu as ContextMenu;

            if (contextMenu != null)
            {
                contextMenu.Placement       = near ? PlacementMode.Bottom : PlacementMode.MousePoint;
                contextMenu.PlacementTarget = near ? this : null;
                contextMenu.IsOpen          = true;
                return(true);
            }

            var command = Command;

            if (command != null)
            {
                command.Execute(CommandParameter);
                return(true);
            }

            return(false);
        }