WPF标签在包含下划线时获取TextBlock样式

nit*_*ech 5 wpf xaml label

当我在标签文本中包含下划线时,为了获得访问键功能,标签会突然跳过一定数量的像素.

两个标签彼此相对,一个具有额外的PaddingLeft

当我在Kaxaml尝试了这一点,我意识到这是一个StyleTargetType="TextBlock"施加保证金,只有在它与下划线的标签.

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

这里的逻辑是什么?在你添加下划线之前,某种标签不是TextBlock吗?