protected override void OnContextMenuOpening(ContextMenuEventArgs e) { this.SelectedLink = boxOutput.SelectedLink; if (!string.IsNullOrEmpty(this.SelectedLink)) { if (Constants.UrlRegex.IsMatch(this.SelectedLink)) { boxOutput.ContextMenu = this.Resources["cmHyperlink"] as ContextMenu; } else { if (this.Type == ChatPageType.DccChat) { return; } this.SelectedLink = this.GetNickWithoutLevel(this.SelectedLink); boxOutput.ContextMenu = this.Resources["cmNickname"] as ContextMenu; } boxOutput.ContextMenu.IsOpen = true; e.Handled = true; } else { boxOutput.ContextMenu = this.GetDefaultContextMenu(); if (this.IsServer && boxOutput.ContextMenu != null) { boxOutput.ContextMenu.Items.Refresh(); } } base.OnContextMenuOpening(e); }
private void listView2_ContextMenuOpening(object sender, ContextMenuEventArgs e) { if (listView2.SelectedItems == null || listView2.SelectedItems.Count == 0) { e.Handled = true; return; } System.Windows.Controls.ListBox src = e.Source as System.Windows.Controls.ListBox; src.ContextMenu.Items.Clear(); MenuItem m = new MenuItem(); m.Foreground = Brushes.Black; m.Header = "Download selected items"; m.Command = Model.Download; m.CommandParameter = listView2.SelectedItems; src.ContextMenu.Items.Add(m); /* m = new MenuItem(); m.Foreground = Brushes.Black; m.Header = "View in share"; m.Command = Model.ViewShare; m.CommandParameter = listView2.SelectedItems; src.ContextMenu.Items.Add(m);*/ }
private void RichTextBoxContextMenuClosing(object sender, ContextMenuEventArgs e) { foreach (Control menuItem in dynamicContextMenuItems) { contextMenu.Items.Remove(menuItem); } }
private void listFilters_ContextMenuOpening(object sender, ContextMenuEventArgs e) { if (listFilters.SelectedIndex==-1) { e.Handled = true; } }
void treeView_ContextMenuOpening(object sender, ContextMenuEventArgs e) { SharpTreeNode[] selectedNodes = treeView.GetTopLevelSelection().ToArray(); if (selectedNodes.Length == 0) return; ContextMenu menu = new ContextMenu(); foreach (var category in entries.OrderBy(c => c.Metadata.Order).GroupBy(c => c.Metadata.Category)) { if (menu.Items.Count > 0) { menu.Items.Add(new Separator()); } foreach (var entryPair in category) { IContextMenuEntry entry = entryPair.Value; if (entry.IsVisible(selectedNodes)) { MenuItem menuItem = new MenuItem(); menuItem.Header = entryPair.Metadata.Header; if (!string.IsNullOrEmpty(entryPair.Metadata.Icon)) { menuItem.Icon = new Image { Width = 16, Height = 16, Source = Images.LoadImage(entry, entryPair.Metadata.Icon) }; } if (entryPair.Value.IsEnabled(selectedNodes)) { menuItem.Click += delegate { entry.Execute(selectedNodes); }; } menu.Items.Add(menuItem); } } } if (menu.Items.Count > 0) treeView.ContextMenu = menu; }
private static void ContextMenu_Showing(SystemOptionsView systemOptionsView, object sender, ContextMenuEventArgs e) { if (e.ContextMenuGroupCollection.Any(c => c.Type == ContextMenuGroupType.Custom)) { return; } var cmd = new Telerik.Windows.Documents.RichTextBoxCommands.InsertPictureCommand(systemOptionsView.HTMLRichTextBox); var insertImageMenuItem = new RadMenuItem { Header = "Insert Image...", Command = cmd, Icon = new Image() { Source = new BitmapImage(new Uri("/Cebos.Veyron.Common.SL;component/Assets/Icons/presentation.png", UriKind.Relative)), //// This is valid too, if the image is within the same assembly //Source = new BitmapImage(new Uri("Images/MenuIcons/Clear.png", UriKind.Relative)), Stretch = Stretch.Fill } }; var customContextMenuGroup = new ContextMenuGroup { insertImageMenuItem }; e.ContextMenuGroupCollection.Add(customContextMenuGroup); var textFormatting = e.ContextMenuGroupCollection.FirstOrDefault(x => x.Type == ContextMenuGroupType.FloatingBlockCommands); if (textFormatting != null) { e.ContextMenuGroupCollection.Remove(textFormatting); } }
protected override void OnContextMenuOpening(ContextMenuEventArgs e) { var treeNode = this.SelectedItem as ModelCollectionTreeNode; if (treeNode != null) { treeNode.ShowContextMenu(); } }
private void DataGridContextMenuOpening(object sender, ContextMenuEventArgs e) { var element = e.OriginalSource as FrameworkElement; var dg = (MultiSelector)sender; if (element != null && element.DataContext is ITrack) { var commandbar = new CommandBar(); if (dg.SelectedItems.Count == 1) { var track = (ITrack)dg.SelectedItems[0]; _eventAggregator.GetEvent<TrackCommandBarEvent>().Publish(new TrackCommandBarModel(track, commandbar)); } else if (dg.SelectedItems.Count > 1) { var tracks = dg.SelectedItems.Cast<ITrack>(); _eventAggregator.GetEvent<TracksCommandBarEvent>().Publish(new TracksCommandBarModel(tracks, commandbar)); } dg.ContextMenu = new CommandBarContextMenu { ItemsSource = commandbar.ChildMenuItems }; } }
private void MainWindowContextMenuOpening(object sender, ContextMenuEventArgs e) { var fe = sender as FrameworkElement; var _scriptingUIHelper = CompositionManager.Get<IScriptingUIHelper>(); var _scriptingConfiguration = CompositionManager.Get<IScriptingConfiguration>(); if (fe == null) return; var newcontextualmenu = new ContextMenu(); if (_scriptingUIHelper != null) { List<object> menu = _scriptingUIHelper.CreateContextMenusFromScripts(false, _scriptingConfiguration. MainWindowContextMenuEntryPoint, MenuItemClick); if (menu != null) { foreach (object i in menu) newcontextualmenu.Items.Add(i); } } fe.ContextMenu = newcontextualmenu; }
private void contextMenuSelectedTextOpening(object sender, ContextMenuEventArgs e) { var fe = sender as FrameworkElement; var newcontextualmenu = new ContextMenu(); var _scriptingUIHelper = CompositionManager.Get<IScriptingUIHelper>(); var _scriptingConfiguration = CompositionManager.Get<IScriptingConfiguration>(); var ewf = Keyboard.FocusedElement as UIElement; // this retrieves the current textbox that has selection if (ewf is CompositionTextBox) // if it is a compositiontextbox { var tbwf = ewf as RichTextBox; var spellingSuggestions = tbwf.GetSpellingError(tbwf.CaretPosition); if (spellingSuggestions != null) { if (spellingSuggestions.Suggestions.HasItems()) { foreach (string str in spellingSuggestions.Suggestions) { var mi = new MenuItem { Header = str, FontWeight = FontWeights.Bold, Command = EditingCommands.CorrectSpellingError, CommandParameter = str, CommandTarget = tbwf }; newcontextualmenu.Items.Add(mi); } } else { var mi = new MenuItem {Header = "No Suggestions", FontWeight = FontWeights.Bold, IsEnabled = false}; newcontextualmenu.Items.Add(mi); } newcontextualmenu.Items.Add(new Separator()); } } if (_scriptingUIHelper != null) { _scriptingUIHelper.createCCPContextualMenus(newcontextualmenu, contextMenuItem_StandardCCP); var menu = _scriptingUIHelper.CreateContextMenusFromScripts(true, _scriptingConfiguration. ComposeTextContextMenuEntryPoint, mi_TextSelect_Click); if (menu != null) { foreach (object i in menu) newcontextualmenu.Items.Add(i); } } if (fe != null) fe.ContextMenu = newcontextualmenu; }
protected override void OnContextMenuOpening(ContextMenuEventArgs e) { this.ContextMenu.ItemsSource = ContextMenuOptions; if (this.ContextMenu.Items.Count == 0) e.Handled = true; base.OnContextMenuOpening(e); }
private void _OnContextMenuOpening(object sender, ContextMenuEventArgs e) { try { // _UpdateContextMenuItemsStatus(sender as Button); } catch { } }
//Not Needed anymore since WindowChrome is Doing the Job now protected override void OnContextMenuOpening(ContextMenuEventArgs e) { //if (e.Handled) // return; //var source = PresentationSource.FromVisual(this) as HwndSource; //if (source != null) // ModernChromeWindow.ShowWindowMenu(source, this, Mouse.GetPosition(this), RenderSize); //e.Handled = true; }
void FrameworkElement_ContextMenuOpening(object sender, ContextMenuEventArgs e) { if (IsIgnored(sender, e)) return; bool? b = menuService.ShowContextMenu(e, element, ctxMenuGuid, ctxMenuGuid, new GuidObject(guid, element), provider, initCtxMenu, e.CursorLeft == -1 && e.CursorTop == -1); if (b == null) return; if (!b.Value) e.Handled = true; }
private void OnContextMenuOpening(object sender, ContextMenuEventArgs e) { var commit = GetCurrentSelectedCommit(); if (commit == null) { e.Handled = true; return; } }
private static void OnDocumentViewerContextMenuOpening(object sender, ContextMenuEventArgs e) { if (e.CursorLeft == KeyboardInvokedSentinel) { DocumentViewer dv = sender as DocumentViewer; if (dv != null && dv.ScrollViewer != null) { OnContextMenuOpening(dv.ScrollViewer.Content, e); } } }
/// <summary> /// Opens the shell context menu instead of the normal context menu on right click. /// </summary> static void OnContextMenuOpening(object sender, ContextMenuEventArgs e) { Control control = sender as Control; // Attempt to open the explorer context menu for the application. If the file does not exist or // there is some other problem then a context menu (defined in the XAML) with just "Edit Entry" // and "Remove Entry" is opened instead. if (control != null && control.DataContext is ApplicationViewModel) { ApplicationViewModel application = (ApplicationViewModel)control.DataContext; if (File.Exists(application.FilePath)) { ContextMenuWrapper cmw = new ContextMenuWrapper(); cmw.OnQueryMenuItems += (QueryMenuItemsEventHandler)delegate(object s, QueryMenuItemsEventArgs args) { args.ExtraMenuItems = new string[] { "Edit Dock Entry", "Remove Dock Entry", "---" }; args.GrayedItems = new string[] { "delete", "rename", "cut", "copy" }; args.HiddenItems = new string[] { "link" }; args.DefaultItem = 1; }; cmw.OnAfterPopup += (AfterPopupEventHandler) delegate(object s, AfterPopupEventArgs args) { Messenger.Default.Send<ShellContextMenuMessage>(ShellContextMenuMessage.Closed()); }; Messenger.Default.Send<ShellContextMenuMessage>(ShellContextMenuMessage.Opened()); try { FileSystemInfoEx[] files = new[] { FileInfoEx.FromString(application.FilePath) }; int[] position = Win32Mouse.GetMousePosition(); string command = cmw.Popup(files, new System.Drawing.Point(position[0], position[1])); // Handle the click on the 'ExtraMenuItems'. switch (command) { case "Edit Dock Entry": Messenger.Default.Send<ApplicationMessage>(ApplicationMessage.Edit(application)); break; case "Remove Dock Entry": Messenger.Default.Send<ApplicationMessage>(ApplicationMessage.Remove(application)); break; } e.Handled = true; // Don't open the normal context menu. } catch (Exception ex) { Debug.Print("Problem displaying shell context menu: {0}", ex); } } } }
private void HandlerForCMO2(object sender, ContextMenuEventArgs e) { if (!_flagForCustomContextMenu) { e.Handled = true; //need to suppress empty menu var fe = e.Source as FrameworkElement; fe.ContextMenu = BuildMenu(); _flagForCustomContextMenu = true; fe.ContextMenu.IsOpen = true; } }
private void MainTree_ContextMenuOpening(object sender, ContextMenuEventArgs e) { if (MainTree.SelectedItem == null) { e.Handled = true; return; } var item = (IMainTreeItem) ((TreeViewItem) MainTree.SelectedItem).Tag; item.CreateContextMenu(); }
int mousepos_whenmenuopened = -1; // The mouse position (as a text offset) upon context menu opening; -1 = could not be determined private void txtCodeContextMenu_ContextMenuOpening(object sender, ContextMenuEventArgs e) { // the mouse position upon context menu opening is stored in mousepos_whenmenuopened Nullable<TextViewPosition> vp = txtCode.TextArea.TextView.GetPosition(new Point(e.CursorLeft, e.CursorTop)); if (vp != null) { mousepos_whenmenuopened = txtCode.Document.GetOffset(vp.Value.Line, vp.Value.Column); } else mousepos_whenmenuopened = -1; }
private void listItems_ContextMenuOpening(object sender, ContextMenuEventArgs e) { Item item = listItems.SelectedItem as Item; if (item != null) { menuItemFile.Visibility = item.FileName == string.Empty ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible; } else { e.Handled = true; } }
void ListViewEx_ContextMenuOpening(object sender, ContextMenuEventArgs e) { if (sender is ListViewEx) { bool headerClick = false; if (e.OriginalSource is FrameworkElement) { FrameworkElement src = (FrameworkElement)e.OriginalSource; while (src != null) { if (src.TemplatedParent is GridViewColumnHeader) { src = null; headerClick = true; } else if (src.TemplatedParent is FrameworkElement) { src = (FrameworkElement)src.TemplatedParent; } else src = null; } } if (headerClick) { e.Handled = true; } else { if (((ListViewEx)sender).SelectedItem is Expanz.DynamicDataObject)//fixme { Expanz.DynamicDataObject dynamicObject = (Expanz.DynamicDataObject)((ListViewEx)sender).SelectedItem; int.TryParse(dynamicObject[Common.IDAttrib].ToString(), out myContextKey); myContextType = dynamicObject[Common.Data.RowType].ToString(); } } } if (myContextType != null && myContextType.Length > 0 && myContextKey > 0) { ActivityHarness.ContextMenuPublisher = this; var elementList = new XElement[2]; var contextElement = CreateRequestElement(Common.Requests.SetContext); contextElement.SetAttributeValue(Common.IDAttrib, myContextKey); contextElement.SetAttributeValue(Common.Data.RowType, myContextType); //contextElement.SetAttributeValue(Common.SetIdFromContextAttribute, "1"); SetContextObject(contextElement); elementList[0] = contextElement; var xmenu = CreateRequestElement(Common.Requests.ContextMenu); elementList[1] = xmenu; _controlHarness.SendXml(elementList); } }
private void AddItemToCm(object sender, ContextMenuEventArgs e) { //check if Item4 is already there, this will probably run more than once var fe = e.Source as FrameworkElement; var cm = fe.ContextMenu; if (cm.Items.Cast<MenuItem>().Any(mi => (string) mi.Header == "Item4")) { return; } var mi4 = new MenuItem {Header = "Item4"}; fe.ContextMenu.Items.Add(mi4); }
// TODO: Hack so the correct context menu is shown in the text view protected override void OnContextMenuOpening(ContextMenuEventArgs e) { ClearValue(ContextMenuProperty); base.OnContextMenuOpening(e); var ctxMenu = ContextMenu; if (ctxMenu != null) { if (IsEnabled) { ctxMenu.PlacementTarget = this; ctxMenu.IsOpen = true; } e.Handled = true; } }
private void tagViewContextMenu(object sender, ContextMenuEventArgs e) { ListBox lb = sender as ListBox; if (tagListBox.SelectedItems.Count > 0) { lb.ContextMenu.Visibility = System.Windows.Visibility.Visible; } else { lb.ContextMenu.Visibility = System.Windows.Visibility.Collapsed; } }
protected override void OnContextMenuOpening(ContextMenuEventArgs e) { base.OnContextMenuOpening(e); var buttonMenu = new ContextMenu(); var mia = new MenuItem {Header = "Item1"}; var mib = new MenuItem {Header = "Item2"}; var mic = new MenuItem {Header = "Item3"}; buttonMenu.Items.Add(mia); buttonMenu.Items.Add(mib); buttonMenu.Items.Add(mic); var fe = e.Source as FrameworkElement; fe.ContextMenu = buttonMenu; }
public override void ShowContextMenu(ContextMenuEventArgs e) { new ContextMenu { ItemsSource = new object[] { MenuCommands.CreateBrowseCode(file.FileName), MenuCommands.CreateAnalyzeThis(file), new Separator(), MenuCommands.CreateCopyUnitName(file), MenuCommands.CreateCopyUnitLocation(file), MenuCommands.CreateCopyThisBranch(this) }, IsOpen = true }; }
private void RichTextBoxContextMenuOpening(object sender, ContextMenuEventArgs e) { List<Control> menuItems = new List<Control>(); SpellingError spellingError = richTextBox.GetSpellingError(richTextBox.CaretPosition); if (spellingError != null) { foreach (string suggestion in spellingError.Suggestions.Take(5)) { MenuItem menuItem = new MenuItem() { Header = suggestion, FontWeight = FontWeights.Bold, Command = EditingCommands.CorrectSpellingError, CommandParameter = suggestion }; menuItems.Add(menuItem); } if (!menuItems.Any()) { MenuItem noSpellingSuggestions = new MenuItem() { Header = Properties.Resources.NoSpellingSuggestions, FontWeight = FontWeights.Bold, IsEnabled = false, }; menuItems.Add(noSpellingSuggestions); } menuItems.Add(new Separator()); MenuItem ignoreAllMenuItem = new MenuItem() { Header = Properties.Resources.IgnoreAllMenu, Command = EditingCommands.IgnoreSpellingError }; menuItems.Add(ignoreAllMenuItem); menuItems.Add(new Separator()); } foreach (Control item in menuItems.Reverse<Control>()) { contextMenu.Items.Insert(0, item); } dynamicContextMenuItems = menuItems; }
void ContextMenu_ContextMenuOpening(object sender, ContextMenuEventArgs e) { var treeView = (sender as TreeView); var contextMenu = treeView.ContextMenu; foreach (MenuItem item in contextMenu.Items) item.Visibility = Visibility.Collapsed; if (treeView.SelectedItem == null) (contextMenu.Items[0] as MenuItem).Visibility = Visibility.Visible; else if ((treeView.SelectedItem as StateViewModel) != null) (contextMenu.Items[contextMenu.Items.Count - 1] as MenuItem).Visibility = Visibility.Visible; else if ((treeView.SelectedItem as DeviceViewModel) != null) for (var i = 0; i < contextMenu.Items.Count - 1; i++) (contextMenu.Items[i] as MenuItem).Visibility = Visibility.Visible; }
public void OnContextMenuOpening(object sender, ContextMenuEventArgs e) { if (sender is Button) { e.Handled = true; return; } var packageViewModel = (PackageViewModel)DataContext; if (packageViewModel == null || packageViewModel.SelectedPackage == null) return; if (packageViewModel.SelectedPackage.IsLocked) e.Handled = true; }
private void TreeContextMenu_ContextMenuOpening(object sender, WC.ContextMenuEventArgs e) { if (treeViewRoot.SelectedItem != null && treeViewRoot.SelectedItem is WC.TreeViewItem item) { if (item.Tag is DirectoryInfo) { menuOpen.IsEnabled = false; menuCreate.IsEnabled = true; } else if (item.Tag is FileInfo) { menuOpen.IsEnabled = true; menuCreate.IsEnabled = false; } } else { menuOpen.IsEnabled = false; menuCreate.IsEnabled = false; } }
private void ContextMenu_ContextMenuOpening(object sender, System.Windows.Controls.ContextMenuEventArgs e) { // disable certain menu items if no map selected bool isMapSelected = (lstMaps.SelectedItem != null); bool isSessionPathValid = SessionPath.IsSessionPathValid(); menuReimporSelectedMap.IsEnabled = isMapSelected; menuOpenSelectedMapFolder.IsEnabled = isMapSelected; menuRenameSelectedMap.IsEnabled = isMapSelected; menuHideSelectedMap.IsEnabled = isMapSelected; menuOpenSessionFolder.IsEnabled = isSessionPathValid; menuOpenMapsFolder.IsEnabled = isSessionPathValid; if (isMapSelected) { MapListItem selected = (lstMaps.SelectedItem as MapListItem); bool hasImportLocation = MetaDataManager.IsImportLocationStored(selected); menuReimporSelectedMap.IsEnabled = hasImportLocation; menuReimporSelectedMap.ToolTip = hasImportLocation ? null : "You can only re-import if you imported the map from 'Import Map > From Computer ...' and imported a folder.\n(does not work with .zip files)"; menuHideSelectedMap.Header = selected.IsHiddenByUser ? "Show Selected Map" : "Hide Selected Map"; if (ViewModel.SecondMapToLoad == null || ViewModel.SecondMapToLoad?.FullPath != selected.FullPath) { menuSecondMapToLoad.Header = "Set As Second Map To Load (When Leaving Apartment)"; menuSecondMapToLoad.ToolTip = "Set the map to be loaded after you leave the apartment (before starting the game)"; } else { menuSecondMapToLoad.ToolTip = "This will clear the selected map to not load after you leave the apartment"; menuSecondMapToLoad.Header = "Clear As Second Map To Load"; } bool canBeDeleted = MetaDataManager.HasPathToMapFilesStored(selected); menuDeleteSelectedMap.IsEnabled = canBeDeleted; } }
private void workItemList_ContextMenuOpening(object sender, System.Windows.Controls.ContextMenuEventArgs e) { var records = GetSelectedTimeRecords(); MungeMenu.IsEnabled = false; ExportMenu.IsEnabled = false; IgnoreMenu.IsEnabled = false; if (records.Count > 0) { if (records.All(x => x.CanExport && !x.IsExported)) { ExportMenu.IsEnabled = true; } if (records.All(x => x.CanIgnore && !x.IsIgnored)) { IgnoreMenu.IsEnabled = true; } if (records.Count > 1 && records.All(x => records.First() is WorkItemTimeRecord && x is WorkItemTimeRecord && (records.First() as WorkItemTimeRecord).Item == (x as WorkItemTimeRecord).Item)) { MungeMenu.IsEnabled = true; } } }
private void OnHeaderContextMenuOpen(object sender, System.Windows.Controls.ContextMenuEventArgs e) { ipList.OnHeaderContextMenuOpen(sender); }
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 }
/// <summary> /// Avoid opening the context menu on ribbons /// </summary> private void RibbonMain_ContextMenuOpening(object sender, System.Windows.Controls.ContextMenuEventArgs e) { e.Handled = true; }
protected override void OnContextMenuOpening(System.Windows.Controls.ContextMenuEventArgs e) { base.OnContextMenuOpening(e); }
private void _notifyIcon_ContextMenuOpening(object sender, System.Windows.Controls.ContextMenuEventArgs e) { }
// show suggestions when user clicks an error protected override void OnContextMenuOpening(System.Windows.Controls.ContextMenuEventArgs e) { // get item that was clicked Point p = new Point(e.CursorLeft, e.CursorTop); var pointer = GetPositionFromPoint(p, true); if (pointer == null) { e.Handled = true; return; } // get error at position foreach (var error in _errorRanges) { if (error.Contains(pointer)) { // get context menu if (ContextMenu == null) { ContextMenu = new ContextMenu(); } var ctx = ContextMenu; ctx.Tag = error; // update context menu with suggestions ctx.Items.Clear(); foreach (var suggestion in _spell.GetSuggestions(error.Text)) { var item = new MenuItem(); item.Header = suggestion; item.FontWeight = FontWeights.Bold; item.Click += suggestion_Click; ctx.Items.Add(item); } if (ctx.Items.Count == 0) { var item = new MenuItem(); item.Header = MENU_NOSUGGESTIONS; item.IsEnabled = false; ctx.Items.Add(item); } // update context menu with spell commands ctx.Items.Add(new Separator()); foreach (string s in new string[] { MENU_IGNOREALL, MENU_ADDTODICTIONARY }) { var item = new MenuItem(); item.Header = s; item.Click += item_Click; ctx.Items.Add(item); } // done break; } } // fire event as usual base.OnContextMenuOpening(e); }
protected override void OnContextMenuOpening(ContextMenuEventArgs e) { }
private void OnContextMenuOpening(object sender, System.Windows.Controls.ContextMenuEventArgs e) { e.Handled = !ContextMenuEnabled; }