2012-09-28 105 views
2

我有一個設計師的樣式指南,看起來像一個超鏈接的按鈕,我試圖儘可能接近WPF樣式。如何更改WPF TextBlock中文本和下劃線之間的距離?

但我一直無法改變文本和下劃線之間的距離。 我想添加圖片進行比較,但不幸的是我迄今尚未獲得足夠的積分。

有沒有辦法改變文字和下劃線之間的距離?

這裏是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> 
+1

在你的第二個TextBlock中添加保證金=「0,5,0,0」 –

+0

@FlorianGl:對不起,我讓你感到困惑與兩個TextBlocks。看到接受的答案。 –

回答

3

使用element syntaxTextDecoration一個實例添加到TextBlock.TextDecorations,則可以調整LocationPenOffset

<TextBlock> 
    <TextBlock.TextDecorations> 
     <TextDecoration Pen="..." Location="..."/> 
    </TextBlock.TextDecorations> 
</TextBlock> 

(您可能需要通過元素語法來設置Pen爲好)

+0

感謝您的回答,它的工作原理! –

0

您可以通過添加它們之間或通過設置Margin一個Separator做到這一點。

分隔符:

<StackPanel Orientation="Horizontal"> 
    <TextBlock Text="&gt; "/> 
    <Separator Width="5" Visibility="Hidden" /> 
    <TextBlock TextDecorations="Underline"> 
     <ContentPresenter/>       
    </TextBlock> 
</StackPanel> 

保證金:

<StackPanel Orientation="Horizontal"> 
    <TextBlock Text="&gt; " Margin="0,0,5,0" /> 
    <TextBlock TextDecorations="Underline"> 
     <ContentPresenter/>       
    </TextBlock> 
</StackPanel> 
+0

對不起,我把你和兩個TextBlocks混淆了。請參閱接受的答案。 –

相關問題