标签不显示"_"特点 [英] Label doesn't display "_" character

查看:84
本文介绍了标签不显示"_"特点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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中用于表示访问键,即您可以使用 Alt 按下以显示焦点或调用的键UI元素.这类似于在Windows API和Windows窗体中使用&的方式.由于标签旨在用作另一个控件的标签(例如,描述文本框),因此非常期望.按下 Alt 时,您应该在示例中看到带下划线的a.

_ is used in WPF to signal an access key, i.e. a key you can press with Alt 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 Alt.

文档:

要设置访问键,请在应作为访问键的字符之前添加下划线.如果您的内容包含多个下划线字符,则只有第一个下划线字符会被转换为访问密钥;否则,只有第一个转换为访问密钥.其他下划线显示为普通文本.如果要转换为访问键的下划线不是第一个下划线,请对要转换的下划线之前的任何下划线使用两个连续的下划线.例如,以下代码包含一个访问密钥,并显示为_HelloWorld:

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> 

由于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.

这篇关于标签不显示"_"特点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆