Example #1
0
        private bool RaiseContextMenuOpeningEvent(IInputElement source, double x, double y, bool userInitiated)
        {
            ContextMenuEventArgs contextMenuEventArgs = new ContextMenuEventArgs(source, true, x, y);
            DependencyObject     dependencyObject     = source as DependencyObject;

            if (userInitiated && dependencyObject != null)
            {
                if (InputElement.IsUIElement(dependencyObject))
                {
                    ((UIElement)dependencyObject).RaiseEvent(contextMenuEventArgs, userInitiated);
                }
                else if (InputElement.IsContentElement(dependencyObject))
                {
                    ((ContentElement)dependencyObject).RaiseEvent(contextMenuEventArgs, userInitiated);
                }
                else if (InputElement.IsUIElement3D(dependencyObject))
                {
                    ((UIElement3D)dependencyObject).RaiseEvent(contextMenuEventArgs, userInitiated);
                }
                else
                {
                    source.RaiseEvent(contextMenuEventArgs);
                }
            }
            else
            {
                source.RaiseEvent(contextMenuEventArgs);
            }
            if (contextMenuEventArgs.Handled)
            {
                this.RaiseToolTipClosingEvent(true);
                return(true);
            }
            DependencyObject targetElement = contextMenuEventArgs.TargetElement;

            if (targetElement != null && ContextMenuService.ContextMenuIsEnabled(targetElement))
            {
                object      contextMenu  = ContextMenuService.GetContextMenu(targetElement);
                ContextMenu contextMenu2 = contextMenu as ContextMenu;
                contextMenu2.SetValue(PopupControlService.OwnerProperty, targetElement);
                contextMenu2.Closed += this.OnContextMenuClosed;
                if (x == -1.0 && y == -1.0)
                {
                    contextMenu2.Placement = PlacementMode.Center;
                }
                else
                {
                    contextMenu2.Placement = PlacementMode.MousePoint;
                }
                this.RaiseToolTipClosingEvent(true);
                contextMenu2.SetCurrentValueInternal(ContextMenu.IsOpenProperty, BooleanBoxes.TrueBox);
                return(true);
            }
            return(false);
        }
Example #2
0
 // Token: 0x06004455 RID: 17493 RVA: 0x00137172 File Offset: 0x00135372
 private void OnPopupUnloaded(object sender, RoutedEventArgs e)
 {
     if (this.IsOpen)
     {
         base.Dispatcher.BeginInvoke(DispatcherPriority.Send, new DispatcherOperationCallback(delegate(object arg)
         {
             ContextMenu contextMenu = (ContextMenu)arg;
             if (contextMenu.IsOpen)
             {
                 contextMenu.SetCurrentValueInternal(ContextMenu.IsOpenProperty, BooleanBoxes.FalseBox);
             }
             return(null);
         }), this);
     }
 }
Example #3
0
        private void OnPopupUnloaded(object sender, RoutedEventArgs e)
        {
            // The tree that the ContextMenu is in is being torn down, close the menu.

            if (IsOpen)
            {
                // This will be called during a tree walk, closing the menu will cause a tree change,
                // so post for later.
                Dispatcher.BeginInvoke(DispatcherPriority.Send,
                                       (DispatcherOperationCallback) delegate(object arg)
                {
                    ContextMenu cm = (ContextMenu)arg;
                    if (cm.IsOpen)     // Check that the menu is still open
                    {
                        cm.SetCurrentValueInternal(IsOpenProperty, BooleanBoxes.FalseBox);
                    }
                    return(null);
                },
                                       this);
            }
        }
Example #4
0
        private bool RaiseContextMenuOpeningEvent(IInputElement source, double x, double y, bool userInitiated)
        {
            // Fire the event
            ContextMenuEventArgs args     = new ContextMenuEventArgs(source, true /* opening */, x, y);
            DependencyObject     sourceDO = source as DependencyObject;

            if (userInitiated && sourceDO != null)
            {
                if (InputElement.IsUIElement(sourceDO))
                {
                    ((UIElement)sourceDO).RaiseEvent(args, userInitiated);
                }
                else if (InputElement.IsContentElement(sourceDO))
                {
                    ((ContentElement)sourceDO).RaiseEvent(args, userInitiated);
                }
                else if (InputElement.IsUIElement3D(sourceDO))
                {
                    ((UIElement3D)sourceDO).RaiseEvent(args, userInitiated);
                }
                else
                {
                    source.RaiseEvent(args);
                }
            }
            else
            {
                source.RaiseEvent(args);
            }


            if (!args.Handled)
            {
                // No one handled the event, auto show any available ContextMenus

                // Saved from the bubble up the tree where we looked for a set ContextMenu property
                DependencyObject o = args.TargetElement;
                if ((o != null) && ContextMenuService.ContextMenuIsEnabled(o))
                {
                    // Retrieve the value
                    object      menu = ContextMenuService.GetContextMenu(o);
                    ContextMenu cm   = menu as ContextMenu;
                    cm.SetValue(OwnerProperty, o);
                    cm.Closed += new RoutedEventHandler(OnContextMenuClosed);

                    if ((x == -1.0) && (y == -1.0))
                    {
                        // We infer this to mean that the ContextMenu was opened with the keyboard
                        cm.Placement = PlacementMode.Center;
                    }
                    else
                    {
                        // If there is a CursorLeft and CursorTop, it was opened with the mouse.
                        cm.Placement = PlacementMode.MousePoint;
                    }

                    // Clear any open tooltips
                    RaiseToolTipClosingEvent(true /*reset */);

                    cm.SetCurrentValueInternal(ContextMenu.IsOpenProperty, BooleanBoxes.TrueBox);

                    return(true); // A menu was opened
                }

                return(false); // There was no menu to open
            }

            // Clear any open tooltips since someone else opened one
            RaiseToolTipClosingEvent(true /*reset */);

            return(true); // The event was handled by someone else
        }