一个非常简单的问题:
为什么我不能_在WPF内容中看到(下划线)?
例如,内容
<Label Content="test_t" Name="label2" />
Run Code Online (Sandbox Code Playgroud)
显示为"testt"(下划线未显示).
Tim*_*oyd 34
标签支持助记符(即您可以使用ctrl+ (key)来给予焦点).您可以使用下划线定义助记键.
http://www.charlespetzold.com/blog/2006/01/061004.html
如果要查看下划线,请使用双下划线替换单个下划线.
这是因为Label支持基于其内容定义助记符,这是通过在助记符前加下划线来完成的(与Windows窗体中的内容相同&).
如果要显示文字,请使用双下划线:
<Label Content="test__t" Name="label2" />
Run Code Online (Sandbox Code Playgroud)
我知道我迟到了,但我相信如果你没有与 TextBox 关联的标签,那么你应该使用 TextBlock 代替。
将控件更改为 TextBlock 可以解决此问题,因为只有 Label 具有助记符支持
小智 5
这种风格可以解决您的问题:
<Style x:Key="{x:Type Label}"
TargetType="{x:Type Label}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Label}">
<Border Background="{TemplateBinding Background}"
BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}"
Padding="{TemplateBinding Padding}"
SnapsToDevicePixels="true">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
RecognizesAccessKey="False"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled"
Value="false">
<Setter Property="Foreground"
Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
Run Code Online (Sandbox Code Playgroud)