This is a migrated thread and some comments may be shown as answers.

Avoid shortcut key in button's content

1 Answer 117 Views
Buttons
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 19 Sep 2012, 02:20 PM
I use a RadButton in a GridView and its content is set to a strings, that contain an underscore ('_'), e.g. 'CT_SRV_ERROR_700'.
Instead of the given string the content of the button is shown without the first underscore, in the example as 'CTSRV_ERROR_700'.
Pressing 'Alt' the first underscore appears as a shortcut key, that means the 'S' is underlined.

I would like to have the content as is, that means with the first '_' shown. Shortcut keys are not necessary and not desired.
Could you please help me?

Thanks.

Thomas

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 20 Sep 2012, 03:26 PM
Hello Thomas,

In order not to have an access key you have to escape the "_" symbol in the RadButton's content. The way to escape the underscore symbol is to put another one before it. In your case you need to put double "_" on every place you want a single underscore, because if you make only the first "_" double then the content will look like 'CT_SRVERROR_700' and "E" will be the short key.

Please give this approach a try and write us back if you have more questions.

Kind regards,
Stefan
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

Subeetha
Top achievements
Rank 1
commented on 26 Jan 2023, 09:00 AM

Hi,

Is there a way to stop considering '_' short key representation? 

In our application, we are generating context menu dynamically based on the user entries. So, user wants to the show the entered text(for example Test_1) as it is in context menu instead Test1.  

Best Regards,

Subeetha

 

Vladimir Stoyanov
Telerik team
commented on 30 Jan 2023, 03:21 PM

The functionality of the "_" character turning the next letter into an access key comes from the RecognizesAccessKey property of the ContentPresenter. The ContentPresenter inside the ControlTemplate of the RadMenuItem has its RecognizesAccessKey property set to True.

With this in mind, you can consider extracting and updating the ControlTemplate of the RadMenuItem to set the RecognizesAccessKey property of the ContentPresenter inside it to False. Alternatively, you can also obtain a reference to the ContentPresenter when a menu item is loaded via the ChildrenOfType extension method and set its property like that. 

Tags
Buttons
Asked by
Thomas
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or