How to assign shortcuts to RadMenuItem?
1 Answer 10 Views
Hoang
Top achievements
Rank 1
Hoang asked on 03 Jun 2021, 01:24 AM

My problem is that when assigning 3 or more shortcuts it comes out "None" even though I have referenced how to initialize the shortcut for RadMenu

This is my code and result image

Thank for reading


            

this.FSaveAs.Name = "FSaveAs"; this.FSaveAs.Text = "Save As"; this.FSaveAs.Click += new System.EventHandler(this.FSaveAs_Click); this.FSaveAs.Shortcuts.Add(new RadShortcut(Keys.Control, Keys.Shift, Keys.S));

1 Answer, 1 is accepted

Sort by
1
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Jun 2021, 07:01 AM
 Hello, Hoang,

The RadMenuItem internally has a RadMenuItemLayout. Its Shortcut TextPrimitive is bound to the Shortcuts collection:

layout.Shortcut.BindProperty(TextPrimitive.TextProperty, this, RadMenuItem.HintTextProperty, PropertyBindingOptions.OneWay);

The Shortcuts.GetDisplayText() method controls what will be displayed by default.

The menu item's Text displays what is set to the RadMenuItem.HintText property: 

            this.radMenuItem1.Shortcuts.Add(new RadShortcut(Keys.Control, Keys.Shift, Keys.S));
            this.radMenuItem1.HintText = "Ctrl + Shift + S";

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Hoang
Top achievements
Rank 1
commented on 03 Jun 2021, 08:47 AM

It shows up normally, but when I press the shortcut, it doesn't work, what's wrong with my code?
Dess | Tech Support Engineer, Principal
Telerik team
commented on 03 Jun 2021, 10:16 AM

Hello,  Hoang,

The first parameter in the RadShortcut constructor is the key modifier. The rest of the passed keys are the key mappings. However, Control and Shift are both key modifiers. Hence, if you want to the shortcut combination to be Ctrl+Shift+S, the proper way to define it is as follows:

this.radMenuItem1.Shortcuts.Add(new RadShortcut(Keys.Control | Keys.Shift, Keys.S));

This will trigger the menu item's Click event on my end:

 Should you have further questions please let me know.
Hoang
Top achievements
Rank 1
commented on 03 Jun 2021, 01:18 PM

Solved, thank you so much!
Tags
Menu
Asked by
Hoang
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or