WPF 中不显示下划线
在我的整个应用程序中,我有一些未显示的下划线 (_)。
这是由于访问器。但我怎样才能禁用它呢?应用广泛?我的标签、文本框上没有它们……
谢谢
On my whole application, I've some underscores (_) which are not displayed.
It's due to the accessor. But how can I disable it? Application wide? I don't have them on labels, textboxes, ...
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
要为所有标签全局禁用下划线,您可以覆盖标签的默认模板,如下所示:
它与此行中的默认模板不同:
RecognizesAccessKey="False"
。将此样式放入应用程序的全局资源 (
App.xaml
) 中,您的标签将不再识别下划线。To disable underscores globally for all labels you can override the default template for labels like this:
It differs from the default template in this line:
RecognizesAccessKey="False"
.Put this style in global resources of your application (
App.xaml
) and your labels will not recognize underscores anymore.使用两个下划线:
Use two underscores:
一种简单的解决方案是不使用
One easy solution is to not use <Label>. <TextBox> doesn't mess with underscores.
您是否尝试过加倍下划线?
Have you tried doubling the underscores?
我遇到了同样的问题
Button
&Label
控制内容中下划线不显示的位置。我还希望在不改变按钮或标签的外观和感觉的情况下进行修复。我从 Stackoverflow 上的这个问题中得到了这个想法。我尝试使用双下划线
,但是当您尝试访问标签或按钮的内容时,它遇到了问题,您现在必须将双下划线转换为单下划线。我使用通过样式应用于 ContentControl 的 DataTemplate 实现了该解决方案。我为 ContentPresenter 设置了 RecognizesAccessKey="False"。
Button
控件派生自具有 Content 属性的ContentControl
。因此,我们必须使用BasedOn
属性将样式应用于它们,如代码所示。以下是修复前后的 UI 外观:
这是MainWindow.xaml要测试的代码:
I ran into the same problem for
Button
&Label
Control where the underscore inside the content was not displayed. I also want the fix without changing the look and feel of the Button or Label. I got the idea from this question on Stackoverflow. I tried usingdoubling the underscores
, but it had its issues when you tried to access the content of the label or button you now have to convert double underscore to single.I implemented the solution using DataTemplate applied through style to ContentControl. I set
RecognizesAccessKey="False"
for the ContentPresenter.As bothLabel
&Button
control derive fromContentControl
with Content Property. So We have to apply the style to them using theBasedOn
attribute as shown in the code.Here is how the UI looks before and after the fix:
Here is the code for MainWindow.xaml to test: