2

I am attempting to assign the following string to a label created in XAML from the C# code-behind file: "Recall_AUX_002"

To do this, I am using the following:

lblRecall.Content = currentAddress.Recall;

When I run the program, the first underscore magically disappears and the result becomes "RecallAUX_002." If I try to assign the same variable to a random text box in the form, with the following code, it works fine:

txtGivenName.Content = currentAddress.Recall;

Why is the underscore randomly being removed in labels?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
tsmith18256
  • 628
  • 1
  • 6
  • 13
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Dec 16 '14 at 17:31

2 Answers2

2

This is because Windows thinks that the first "_" character is an "Access Key". That is, its the key that if you hold down Alt it is the character that is underlined.

You can escape it by writing two underscores:

<Label Content="Recall__AUX_002"/>

or by turning the RecognizeAccessKey property to false. This is in the content presenter, so you have to modify the ControlTemplate

You can also always just switch to using a TextBlock, which ignores access keys.

BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117
1

Underscore are considered as access keys. It has to be disabled if you like to display it in the content.

Refer the below link Underscores not displayed in WPF

Community
  • 1
  • 1
Ayyappan Subramanian
  • 5,348
  • 1
  • 22
  • 44