שתף באמצעות


Underscore in label.content in WPF app

Question

Saturday, August 14, 2010 2:59 PM | 1 vote

I have a series of variable values that use an underscore to represent the space between words (e.g., abc_def_hij or klm_nop). When trying to display them as label.content (e.g., MyLabel.Content = DataType) the label always suppresses the first underscore. The examples I gave would display as abcdef_hij or klmnop and I can't seem to find anything that defines this anomaly or how to alter its behavior. Any ideas? I'm writing a WPF app in VB 2010 Professional

 

Mike

Mike

All replies (4)

Sunday, August 15, 2010 11:25 AM ✅Answered

Thanks

 

I was thinking maybe it was a holdover from previous VB where the underscore was a line continuation character. I didn't consider it was from the action key functionality. I can actually overcome it by simply adding an underscore before my variable name. That's not a very elegant solution, but it works. Can you foresee any problem with my doing so? (e.g., lblMyLabel.content = "_" & DataType)

 

 

Mike


Sunday, August 15, 2010 3:04 PM ✅Answered | 2 votes

According to the docs, putting a single underscore in front of a character in a label makes it the access key: it gets underlined if you press the Alt key. The workaround is to double up all the underscores, e.g., Label1.Content=DataType.Replace("_", "__").

Shame there isn't a property of a label to suppress that behaviour.

--
Andrew


Sunday, August 15, 2010 11:00 AM

Yea got the same result.

http://msdn.microsoft.com/en-us/library/system.windows.controls.label.aspx

I find this strange to handle variables which can even be from a database.

In my perception a very big design error.

 

 

 

Success
Cor


Sunday, August 15, 2010 12:52 PM

I think this is a reasonable workaround, in foreseeing I think we are equal so with that I cannot help you. 

 

Success
Cor