如何更改WPF文本块中文本和下划线之间的距离?
我有一个设计师为一个看起来像超链接的按钮提供的样式指南,我正试图用WPF样式尽可能接近它 但是我无法改变文本和下划线之间的距离。 我想添加图像进行比较,但不幸的是,到目前为止我还没有获得足够的分数 有没有办法改变文本和下划线之间的距离 以下是我到目前为止的XAML代码:如何更改WPF文本块中文本和下划线之间的距离?,wpf,xaml,textblock,underline,Wpf,Xaml,Textblock,Underline,我有一个设计师为一个看起来像超链接的按钮提供的样式指南,我正试图用WPF样式尽可能接近它 但是我无法改变文本和下划线之间的距离。 我想添加图像进行比较,但不幸的是,到目前为止我还没有获得足够的分数 有没有办法改变文本和下划线之间的距离 以下是我到目前为止的XAML代码: <Style x:Key="LinkButton" TargetType="ButtonBase"> <Setter Property="Background" Value="Transparent"/
<Style x:Key="LinkButton" TargetType="ButtonBase">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ButtonBase">
<StackPanel Orientation="Horizontal">
<TextBlock Text="> "/>
<TextBlock TextDecorations="Underline">
<ContentPresenter/>
</TextBlock>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="{StaticResource LxGrayBrush}"/>
<Setter Property="FontSize" Value="12"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Foreground" Value="{StaticResource LxGreenBrush}"/>
</Trigger>
</Style.Triggers>
</Style>
您可以通过在它们之间添加一个或设置 分离器:
<StackPanel Orientation="Horizontal">
<TextBlock Text="> "/>
<Separator Width="5" Visibility="Hidden" />
<TextBlock TextDecorations="Underline">
<ContentPresenter/>
</TextBlock>
</StackPanel>
保证金:
<StackPanel Orientation="Horizontal">
<TextBlock Text="> " Margin="0,0,5,0" />
<TextBlock TextDecorations="Underline">
<ContentPresenter/>
</TextBlock>
</StackPanel>
用于将的实例添加到,然后可以调整或
(您可能还需要通过元素语法设置笔
)
这是我要显示的文本
调整PenOffset将增加/减少文本和线条之间的间距。要使线条比“下划线”更靠近文本,则有“基线”。它比H.B.解决方案灵活得多,但也更简单
<TextBlock TextDecorations="Baseline" />
在你的第二个文本块中添加Margin=“0,5,0,0”@FlorianGl:对不起,我把你和这两个文本块搞混了。请参阅已接受的答案。对不起,我用两个文本块将您弄糊涂了。请看接受的答案。
<TextBlock >
Here is my text to be displayed
<TextBlock.TextDecorations>
<TextDecoration PenOffset="3" PenOffsetUnit="Pixel"/>
</TextBlock.TextDecorations>
</TextBlock>
<TextBlock TextDecorations="Baseline" />