Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Underscores not displayed in WPF

Tags:

wpf

accessor

On my whole application, I've some underscores (_) which are not displayed.

It's due to the accessor. But how can I disable it? Application wide? I don't have them on labels, textboxes, ...

Thank you

like image 881
J4N Avatar asked Feb 25 '11 12:02

J4N


3 Answers

To disable underscores globally for all labels you can override the default template for labels like this:

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

It differs from the default template in this line: RecognizesAccessKey="False".

Put this style in global resources of your application (App.xaml) and your labels will not recognize underscores anymore.

like image 115
Pavlo Glazkov Avatar answered Oct 21 '22 21:10

Pavlo Glazkov


Use two underscores:

name = "__something";
like image 40
Aliostad Avatar answered Oct 21 '22 20:10

Aliostad


One easy solution is to not use <Label>. <TextBox> doesn't mess with underscores.

like image 32
Jeff Dege Avatar answered Oct 21 '22 19:10

Jeff Dege