下划线未显示在WPF中

J4N*_*J4N 16 wpf accessor

在我的整个应用程序中,我有一些未显示的下划线(_).

这是由于访问者.但是如何禁用它呢?适用范围广?我没有标签,文本框,......

谢谢

Pav*_*kov 19

要为所有标签全局禁用下划线,您可以覆盖标签的默认模板,如下所示:

<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>
</Style>
Run Code Online (Sandbox Code Playgroud)

它与此行中的默认模板不同:RecognizesAccessKey="False".

将此样式放在应用程序的全局资源(App.xaml)中,您的标签将不再识别下划线.


Ali*_*tad 9

使用两个下划线:

name = "__something";
Run Code Online (Sandbox Code Playgroud)

  • 使用值转换器将下划线替换为双下划线.简单. (3认同)

Jef*_*ege 7

一个简单的解决方案是不使用<Label>.<TextBox>不会使下划线混乱.

  • 如果您不想处理可编辑的内容,请使用TextBlock.绑定到"Text"而不是"Content". (6认同)