当WPF标签包含下划线

时间:2016-03-01 10:31:42

标签: wpf xaml label

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

Two labels above each other, one which has extra PaddingLeft

当我在Kaxaml中尝试此操作时,我意识到它是Style TargetType="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>

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

0 个答案:

没有答案