6

Possible Duplicate:
Disable WPF label accelerator key (text underscore is missing)

I am currently working on a C# WPF project. I need to read in a configuration file and display the options retrieved inside a label. The options are sometimes labelled with an underscore (_) in the middle of the option name, for example, it might be something like my_option.

When I try to display my_option inside a label, the underscore is hidden and is instead used as a keyboard shortcut when the Alt key is pressed.

How can I disable this from happening and instead show the underscore in the label?

I have tried doing it so it is my__option (that is, adding two underscores together instead of one), but this doesn't seem to do anything.

Community
  • 1
  • 1
Boardy
  • 35,417
  • 104
  • 256
  • 447
  • Guess: Try escaping the underscore with a backslash – Chris Laplante Jun 25 '11 at 21:25
  • @SimpleCoder, I did try that but it Visual Studio displayed the error that it was an unrecognised escape sequence – Boardy Jun 25 '11 at 21:26
  • Why a label and not a textblock? – Emond Jun 25 '11 at 21:27
  • This, maybe? http://stackoverflow.com/questions/4325094/c-enter-symbol-into-a-text-label – Dr McKay Jun 25 '11 at 21:28
  • @Boardy, then you have to escape the backslash: `\\_`. – svick Jun 25 '11 at 21:29
  • @Dr McKay, that is WinForms this is about WPF. – Emond Jun 25 '11 at 21:34
  • The "exact duplicate" question doesn't answer this question. That question says that `__` works. It also says you can't do what you want with a label. So to answer this question: i dunno - it should work. – Ian Boyd Jun 25 '11 at 21:42
  • @Boardy, could you please post some code that shows this behavior with the double underscores? In my testing I always can get the double underscores to work. If you can post an example where it does not work then we can go from there. – saunderl Jun 25 '11 at 21:47
  • I've got it working based on what @erno said and used a textblock instead of a label. Thanks for your help – Boardy Jun 25 '11 at 21:58

0 Answers0