Select TreeView Node on right click before displaying ContextMenu

Depending on the way the tree was populated, the sender and the e.Source values may vary. One of the possible solutions is to use e.OriginalSource and find TreeViewItem using the VisualTreeHelper: private void OnPreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e) { TreeViewItem treeViewItem = VisualUpwardSearch(e.OriginalSource as DependencyObject); if (treeViewItem != null) { treeViewItem.Focus(); e.Handled = true; } } … Read more

How to add a “open git-bash here…” context menu to the windows explorer?

Step 1. On your desktop right click “New”->”Text Document” with name OpenGitBash.reg Step 2. Right click the file and choose “Edit” Step 3. Copy-paste the code below, save and close the file Step 4. Execute the file by double clicking it Note: You need administrator permission to write to the registry. Windows Registry Editor Version … Read more

Detecting which selected item (in a ListView) spawned the ContextMenu (Android)

I do exactly this. In my onCreateContextMenu(…) method, I cast the ContextMenu.ContextMenuInfo to AdapterView.AdapterContextMenuInfo. From there, you can get the targetView, which you cast again to the widget. The complete code is available in HomeActivity.java, look for the onCreateContextMenu(…) method. @Override public void onCreateContextMenu(ContextMenu contextMenu, View v, ContextMenu.ContextMenuInfo menuInfo) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; … Read more

How to retrieve the element where a contextmenu has been executed

You can inject content script with contextmenu event listener and store element that was clicked: manifest.json “content_scripts”: [{ “matches”: [“<all_urls>”], “js”: [“content.js”], “all_frames”: true, “match_about_blank”: true }] content script.js //content script var clickedEl = null; document.addEventListener(“contextmenu”, function(event){ clickedEl = event.target; }, true); chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { if(request == “getClickedEl”) { sendResponse({value: clickedEl.value}); } }); background.js … Read more

WPF ContextMenu woes: How do I set the DataContext of the ContextMenu?

The ContextMenu is outside of the visual tree. Below is the xaml that should get you the datacontext: <ItemsControl ItemsSource=”{Binding Markers}” Tag=”{Binding ElementName=outerControl, Path=DataContext}”> … <ContextMenu DataContext=”{Binding Path=PlacementTarget.Tag, RelativeSource={RelativeSource Self}}”> <MenuItem Header=”Edit” Command=”{Binding EditCommand}” /> </ContextMenu> … </ItemsControl> This post explains how this works.

EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event

Solution: Override isSuggestionsEnabled and canPaste in EditText. For the quick solution, copy the class below – this class overrides the EditText class, and blocks all events accordingly. For the gritty details, keep reading. The solution lies in preventing PASTE/REPLACE menu from appearing in the show() method of the (non-documented) android.widget.Editor class. Before the menu appears, … Read more