Label doesn't display “_” character

前端 未结 7 1841
别跟我提以往
别跟我提以往 2021-01-01 09:10

My Label.Content in WPF doesn\'t display the first occurrence of \"_\" character. Why?



        
7条回答
  •  轮回少年
    2021-01-01 09:29

    _ is used in WPF to signal an access key, i.e. a key you can press with Alt to give focus or invoke an UI element. This is similar to how & is used in the Windows API and Windows Forms. Since labels are intended to be used as the label for another control (to describe a text box, for example), this is pretty much expected. You should see the a in your example underlined when you press Alt.

    From the documentation:

    To set the access key, add an underscore before the character that should be the access key. If your content has multiple underscore characters, only the first one is converted into an access key; the other underscores appear as normal text. If the underscore that you want converted to the access key is not the first underscore, use two consecutive underscores for any underscores that precede the one that you want to convert. For example, the following code contains an access key and displays as _HelloWorld:

     
    

    Because the underscore that precedes H is a double, the W key registers as the access key.

    I guess if you neither require nor want the features Label provides, you may use a TextBlock.

提交回复
热议问题