突然发现label设置content的值为字符串时,如果字符串中包含_的话,在展示出来时下划线就不见了.
百度了一下,发现了问题根源,说的label的ContentPresenter默认将下划线处理成快捷键了。
解决的办法也很简单,只需要重写label的样式,设置不需要处理成快捷键即可(RecognizesAccessKey=”False”):
1 2 3 4 5 6 7 8 9 10 11 12 13 | <Window.Resources> <Style TargetType="Label"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Label"> <Border> <ContentPresenter RecognizesAccessKey="False"></ContentPresenter> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> |
转载请注明:WPF Label 下划线”_”不显示的问题 - https://shuodatong.com/wpf-label-content_/