gpt4 book ai didi

.net - 标签不显示 "_"字符

转载 作者:行者123 更新时间:2023-12-03 08:45:49 27 4
gpt4 key购买 nike

我的 Label.Content在 WPF 中不显示“_”字符的第一次出现。为什么?

<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>

enter image description here

设置时 Label.Content ="L__abel" :

enter image description here

项目中没有额外的代码。

最佳答案

_在 WPF 中用于表示访问键,即您可以使用 Alt 按下的键以提供焦点或调用 UI 元素。这类似于 &用于 Windows API 和 Windows 窗体。由于标签旨在用作另一个控件的标签(例如,用于描述文本框),因此这在意料之中。您应该看到 a在您的示例中,当您按下 Alt 时会加下划线。
来自 documentation :

To set the access key, add an underscore before the character that should be the access key. If your content has multiple underscore characters, only the first one is converted into an access key; the other underscores appear as normal text. If the underscore that you want converted to the access key is not the first underscore, use two consecutive underscores for any underscores that precede the one that you want to convert. For example, the following code contains an access key and displays as _HelloWorld:

<Label>__Hello_World</Label> 

Because the underscore that precedes H is a double, the W key registers as the access key.


我想如果您既不需要也不想要这些功能 Label提供,您可以使用 TextBlock .

关于.net - 标签不显示 "_"字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9684619/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com