WPF label gets a TextBlock style when it contains an underscore

When I include an underscore in the text of the shortcut to get the functionality of the passkey, the shortcut suddenly jumped a certain number of pixels.

Two inscriptions above each other, one of which has an additional PaddingLeft

When I tried this in Kaxaml, I realized that this is Stylewith TargetType="TextBlock", which applied margin, only to the label with an underscore in it.

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <UserControl.Resources>

      <Style TargetType="TextBlock">
          <Setter Property="VerticalAlignment" Value="Center"/>
          <Setter Property="HorizontalAlignment" Value="Left"/>
          <Setter Property="Margin" Value="5,2,0,1" />
      </Style>

  </UserControl.Resources>
<Grid>  
  <Grid.ColumnDefinitions>
    <ColumnDefinition></ColumnDefinition>
  </Grid.ColumnDefinitions>
  <Grid.RowDefinitions>
    <RowDefinition Height="Auto"></RowDefinition>
    <RowDefinition Height="Auto"></RowDefinition>
  </Grid.RowDefinitions>
  <Label Grid.Column="0" Grid.Row="0">Avfallets _Id:</Label>
  <Label Grid.Column="0" Grid.Row="1">Avfallets Id:</Label>
</Grid>

What is the logic here? Is any shortcut not a TextBlock until you add an underscore to it?

+4
source share

All Articles