我有一个来自设计师的样式指南,用于一个看起来像超链接的按钮,我正在尝试使用 WPF 样式尽可能接近它。
但是我无法更改文本和下划线之间的距离。
我想添加图像进行比较,但不幸的是,到目前为止我还没有获得足够的积分。
有没有办法改变文本和下划线之间的距离?
这是我到目前为止的 XAML 代码:
<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>
最佳答案
使用 element syntax添加 TextDecoration
的实例到 TextBlock.TextDecorations
,然后您可以调整 Location
或 PenOffset
.
<TextBlock>
<TextBlock.TextDecorations>
<TextDecoration Pen="..." Location="..."/>
</TextBlock.TextDecorations>
</TextBlock>
(您可能还需要通过元素语法设置
Pen
)
关于wpf - 如何更改 WPF TextBlock 中文本和下划线之间的距离?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12639139/