WPF中的CheckBox的_ (underscore / 下划线)丢失

今天在项目中遇到check box的Content的内容缺少'_', 原因是WPF的ContentPresenter默认会把‘_’作为加速键的转义字符。 

比如CheckBox的content为“_IsEnable”, 实际结果:

显示为“IsEnable”; 当你按键“i”时,会触发Click事件,就可以快速的选中或者取消选中。


如果想要显示‘_’, 可以将控件内部的ContentPresenter的RecognizesAccessKey设置为”False“,如:

<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}"  RecognizesAccessKey="False" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>

你可能感兴趣的:(underscore,checkbox,WPF,下划线,accesskey)