WPF Textblock文本安排

时间:2016-02-01 05:56:25

标签: c# wpf xaml

我有一个水平对齐的标签和文本框。

 <TextBlock Width="400" Margin="10" Padding="10">
    <Label Foreground="Yellow" FontSize="13" FontWeight="Bold" >Heading:</Label>
    <TextBlock  FontSize="13" TextWrapping="Wrap" FontWeight="Bold" >here is the main contetn and how about adding it to left on seco
        here is the main content and how about adding it to left on seco
    </TextBlock>
</TextBlock>

我可以在标签下方排列文本块的文本 附上示例图片enter image description here

2 个答案:

答案 0 :(得分:4)

我假设你的意思是你希望标题和文本在同一行开始并在标题下溢出。您可以使用“运行”元素在已定义的TextBlock中显示文本来执行此操作。

<TextBlock Width="400" Margin="10" Padding="10" TextWrapping="WrapWithOverflow">
    <Run Foreground="Yellow" FontSize="13" FontWeight="Bold" >Heading:</Run>
    <Run  FontSize="13" FontWeight="Bold" >here is the main contetn and how about adding it to left on seco
        here is the main content and how about adding it to left on seco
    </Run>
</TextBlock>

enter image description here

答案 1 :(得分:0)

使用“堆叠面板”作为标题和网格,其中包含“水平和垂直对齐”属性