Example #1
0
        private void MetadataButton_ContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            if (e != null)
            {
                e.Handled = true;
            }

            ButtonBase button = sender as ButtonBase;

            if ((button != null) && button.IsEnabled)
            {
                button.ContextMenu = null;

                IMetadataViewService metadataViewService = ToolsUIApplication.Instance.RootServiceProvider.GetService(typeof(IMetadataViewService)) as IMetadataViewService;

                if (metadataViewService != null)
                {
                    IEnumerable <MetadataView> metadataViews = metadataViewService.GetMetadataViews(Window.GetWindow(button));
                    if (metadataViews.Count() > 0)
                    {
                        button.Focus();

                        button.ContextMenu = new ContextMenu()
                        {
                            DataContext        = button.CommandParameter,
                            ItemContainerStyle = Resources["MetadataViewSelectorMenuItemStyle"] as Style,
                            ItemsSource        = metadataViews,
                            PlacementTarget    = button,
                            IsOpen             = true,
                        };
                    }
                }
            }
        }
Example #2
0
        /////////////////////////////////////////////////////////////////////////////////

        void EH_SetRedInFocus(object sender, EventArgs e)
        {
            winMoveable.Parent = MdiClient;
            drawBox.Parent     = MdiClient;
            winRead.Parent     = MdiClient;
            winRead.Focus();
        }
Example #3
0
        protected override void OnKeyUp(KeyRoutedEventArgs e)
        {
            if ((e.Key == VirtualKey.GamepadB || e.Key == VirtualKey.Escape) && IsExpanded)
            {
                SetExpanded(false);
                _expanderButton.Focus(FocusState.Programmatic);

                e.Handled = true;
            }

            base.OnKeyUp(e);
        }
Example #4
0
        /// <summary>
        /// Invoked when an unhandled <see cref="Keyboard.KeyDownEvent"/> attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.Windows.Input.KeyEventArgs"/> that contains the event data.</param>
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (e.Handled)
            {
                return;
            }

            if (Keyboard.Modifiers != ModifierKeys.None)
            {
                return;
            }

            if (e.Key == Key.Enter)
            {
                if (_defaultOkElement != null)
                {
                    _defaultOkElement.GotFocus += OnButtonReceivedFocus;
                    if (!_defaultOkElement.Focus())
                    {
                        HandleDefaultButton();
                    }

                    e.Handled = true;
                }
                else if (_defaultOkCommand != null)
                {
                    HandleDefaultButton();
                    e.Handled = true;
                }

                // Else let it go, it's a custom button
            }

            if (e.Key == Key.Escape && CanCloseUsingEscape)
            {
                if (_defaultCancelCommand != null)
                {
                    Log.Info("User pressed 'Escape', executing cancel command");

                    // Not everyone is using the ICatelCommand, make sure to check if execution is allowed
                    if (_defaultCancelCommand.CanExecute(null))
                    {
                        _defaultCancelCommand.Execute(null);
                        e.Handled = true;
                    }
                }
                else
                {
                    Log.Info("User pressed 'Escape' but no cancel command is found, setting DialogResult to false");

                    if (!SetDialogResultAndMakeSureWindowGetsClosed(false))
                    {
                        Close();
                    }

                    e.Handled = true;
                }
            }
        }