This is a migrated thread and some comments may be shown as answers.

WPF Label Content Rendering issue

1 Answer 111 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
cp asked on 09 Dec 2010, 12:11 AM
Setting the content of a label to A_B_C_D for instance renders the text as AB(underlined)_C_D (please see the attached screenshot).

The TreeListView control behaves exactly the same, so I can only assume this applies to all the controls.

How do I make sure my text gets displayed correctly?


1 Answer, 1 is accepted

Sort by
Vanya Pavlova
Telerik team
answered on 09 Dec 2010, 10:01 AM
Hi Claudiu,

You have the following options:

1.In order to display the text A_B_C_D correctly not AB_C_D just add an underscore character at the beginning, refer to the following:

<Grid x:Name="LayoutRoot">
        <Label Content="_A_B_C_D" HorizontalAlignment="Center" VerticalAlignment="Center"/>

2.However putting a single underscore character in front of a character will make this character an access key, if you want to avoid this you may double up all underscores, as it is shown below:

<Label Content="A__B__C__D" HorizontalAlignment="Center" VerticalAlignment="Center"/>

3.Finally if you want to stick to the first soltuion, but if you need to disable the accelerator key for the Label, edit its template and set RecognizesAccessKey property to False within the ContentPresenter:

<Style x:Key="LabelStyle1" TargetType="{x:Type Label}">
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Padding" Value="5"/>
        <Setter Property="HorizontalContentAlignment" Value="Left"/>
        <Setter Property="VerticalContentAlignment" Value="Top"/>
        <Setter Property="Template">
                <ControlTemplate TargetType="{x:Type Label}">
                    <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="False" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>

Vanya Pavlova
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
General Discussions
Asked by
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Share this question