How to configure ContextMenu buttons for delete and disabled in SwiftUI?

All of the asked situations are now supported in iOS 15 Destructive: (works from iOS 15) Set .destructive as the role argument of the button: Button(role: .destructive) { // 👈 This argument // delete something } label: { Label(“Delete”, systemImage: “trash”) } Disabled: (works from iOS 14.2) Add .disabled modifier to the button. Button { … Read more

Find node clicked under context menu

You can add a mouse click event to the TreeView, then select the correct node using GetNodeAt given the mouse coordinates provided by the MouseEventArgs. void treeView1MouseUp(object sender, MouseEventArgs e) { if(e.Button == MouseButtons.Right) { // Select the clicked node treeView1.SelectedNode = treeView1.GetNodeAt(e.X, e.Y); if(treeView1.SelectedNode != null) { myContextMenuStrip.Show(treeView1, e.Location); } } }

How to access a control from a ContextMenu menuitem via the visual tree?

This is happening because DataContext=”{Binding PlacementTarget,… binding would set the button as MenuItems DataContext but that won’t add the ContextMenu to the VisualTree of your window and that’s why ElementName binding’s won’t work. A simple workaround to use ElementName bindings is to add this in your Window/UserControl’s code-behind: NameScope.SetNameScope(contextMenuName, NameScope.GetNameScope(this)); Another solution is to do … Read more

Default ContextMenu Style – WPF

For templates and styles that are not accessible through the Expression Interface (such as the ContextMenu template) you can use the following code to extract the template: Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder Using Writer As TextWriter = New StringWriter(sb) System.Windows.Markup.XamlWriter.Save(ContextMenu.Template, Writer) End Using Debug.Write(sb.ToString) Or in C# var str = new StringBuilder(); using … Read more

WPF ViewModel Commands CanExecute issue

To complete Will’s answer, here’s a “standard” implementation of the CanExecuteChanged event : public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } (from Josh Smith’s RelayCommand class) By the way, you should probably consider using RelayCommand or DelegateCommand : you’ll quickly get tired of creating new … Read more

Copy text from TextView on Android

I think I have a solution. Just call registerForContextMenu(yourTextView); and your TextView will be registered for receiving context menu events. Then override onCreateContextMenu in your Activity: @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { //user has long pressed your TextView menu.add(0, v.getId(), 0, “text that you want to show in the context menu … Read more

WPF Context menu on left click

Here is a XAML only solution. Just add this style to your button. This will cause the context menu to open on both left and right click. Enjoy! <Button Content=”Open Context Menu”> <Button.Style> <Style TargetType=”{x:Type Button}”> <Style.Triggers> <EventTrigger RoutedEvent=”Click”> <EventTrigger.Actions> <BeginStoryboard> <Storyboard> <BooleanAnimationUsingKeyFrames Storyboard.TargetProperty=”ContextMenu.IsOpen”> <DiscreteBooleanKeyFrame KeyTime=”0:0:0″ Value=”True”/> </BooleanAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> </Style.Triggers> <Setter Property=”ContextMenu”> … Read more

Creating a submenu in context menu from overridden getActions in Java JHotDraw

Adding submenus is supported. The class org.jhotdraw.gui.JPopupButton extends JButton to provide the popup menus used throughout the framework. The method add(javax.swing.JMenu submenu) may be used to construct hierarchical submenus. For example, org.jhotdraw.samples.draw.DrawingPanel adds a Zoom submenu to the rightmost popup menu in creationToolbar, along with other miscellaneous editing actions. The method createFontButton() in org.jhotdraw.draw.action.ButtonFactory is … Read more