如何更改文本块的多行以使其具有不同的文本对齐方式

时间:2015-10-23 11:52:16

标签: wpf visual-studio xaml multiline textblock

如何更改每个文本块的行以进行不同的对齐?到目前为止,我有这个代码,但我不知道如何更改第二个和第三个。

<TextBlock Margin="0" Foreground="Red" TextAlignment="Left">
    <Run Text="First Line (Left)"/><LineBreak />
    <Run Text="Second Line (Center)"/><LineBreak />
    <Run Text="Third Line (Right)"/><LineBreak />         
</TextBlock>

1 个答案:

答案 0 :(得分:0)

这将产生类似的结果,但是你将有多个TextBlocks:

<StackPanel Orientation="Vertical">
    <StackPanel Orientation="Vertical">
        <TextBlock Text="First Line (Left)" Margin="0" Foreground="Red" TextAlignment="Left"/>
        <TextBlock Text="Second Line (Center)" Margin="0" Foreground="Red" TextAlignment="Center"/>
        <TextBlock Text="Third Line (Right)" Margin="0" Foreground="Red" TextAlignment="Right"/>
    </StackPanel>
</StackPanel>