问题描述
我在WPF中的Label.Content
不会显示首次出现的"_"字符.为什么?
My Label.Content
in WPF doesn't display the first occurrence of "_" character. Why?
<Window x:Class="WpfApplication3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="148" Width="211">
<Grid>
<Label Content="L_abel" Height="28" HorizontalAlignment="Left" Margin="37,31,0,0" Name="label1" VerticalAlignment="Top" />
</Grid>
</Window>
设置Label.Content ="L__abel"
时:
项目中没有其他代码.
推荐答案
_
在WPF中用于表示访问键,即您可以使用按下以显示焦点或调用的键UI元素.这类似于在Windows API和Windows窗体中使用&
的方式.由于标签旨在用作另一个控件的标签(例如,描述文本框),因此非常期望.按下时,您应该在示例中看到带下划线的a
.
_
is used in WPF to signal an access key, i.e. a key you can press with 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 .
从文档:
<Label>__Hello_World</Label>
由于H之前的下划线是双精度字符,因此W键注册为访问键.
Because the underscore that precedes H is a double, the W key registers as the access key.
我想如果您既不需要也不想要Label
提供的功能,则可以使用TextBlock
.
I guess if you neither require nor want the features Label
provides, you may use a TextBlock
.
这篇关于标签不显示"_"特点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!