WPF TextBlock下划线

我有一个
textblock
width
500
,但我的字符串只是说“H”但我想
underline
整个
textblock
宽度不仅仅在H下我能做什么?     
已邀请:
您应该使用TextBlock的属性“TextDecorations”。像那样:
 <TextBlock Text="H" TextDecorations="Underline"/>
    
只需添加2美分,通过此代码可以在运行时实现与Talia的答案相同的效果:
YourTextBlock.TextDecorations = System.Windows.TextDecorations.Underline;
出于某种原因,VS2010没有显示RHS的Intellisense,但它编译并正确运行。     
        <TextBlock VerticalAlignment="Bottom" 
                   HorizontalAlignment="Center" 
                   Margin="40" 
                   Height="40" 
                   FontSize="16" 
                   Tapped="TextBlock_Tapped"
                   Text="Text"
                   Foreground="{StaticResource LightBlue}">
            <Underline>
                <Run Text="Text"/>
            </Underline>
        </TextBlock>
    
您最好的选择可能是使用位于文本块正下方的矩形,其宽度始终是文本块的宽度。像这样:
<DockPanel LastChildFill="False">
    <TextBlock DockPanel.Dock="Top" x:Name="blockToUnderline" Text="H" Width="76" />
    <Rectangle DockPanel.Dock="Top" Fill="Black" Height=1 Width="{Binding ElementName=blockToUnderline, Path=ActualWidth}" />
</DockPanel>
    

要回复问题请先登录注册