wpf - 如何更改 WPF TextBlock 中文本和下划线之间的距离?

标签 wpf xaml textblock underline

我有一个来自设计师的样式指南,用于一个看起来像超链接的按钮,我正在尝试使用 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="&gt; "/>
                    <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/

相关文章:

.net - XAML 性能 : Set alpha channel of a brush vs. FrameworkElement 的不透明度

c# - 仅在 C# 中更改 Xamarin Forms 标签的颜色,无 XAML

c# - 如何缩小文本 block 中的字体大小以适应内容的宽度并保持字体纵横比

html - 如何仅使用 CSS 在图像上创建文本 block

wpf - 如何在 WPF 应用程序中设置 TextBlock 和标签的默认颜色、字体系列和字体大小?

c# - 如何创建类似于 SO 搜索框的文本框提示

c# - 使某些行在 ViewModel 的 DataGrid 中不可选择

c# - 如何在 DockPanel 中自动调整 TabControl 的大小 - WPF

c# - 如何在没有 Process 类的情况下在 Windows 8 文件资源管理器中打开应用程序文件夹?

c# - Visual Studio 2013 和 C# - 无法添加事件处理程序