如何在一个区域上传播/拉伸文本内容?

时间:2011-07-12 07:39:36

标签: wpf text stretch viewbox spread

在WPF中, 如何在一个区域(宽阔的水平区域)上传播/拉伸内容?

像这样: enter image description here

这是我当前的代码(来自图片的上半部分):

<Grid Width="900">
    <ScrollViewer x:Name="sclScroller" HorizontalScrollBarVisibility="Hidden">
        <Viewbox HorizontalAlignment="Stretch">
            <DockPanel>
                <TextBlock Name="txtContent1" Text="1" />
                <TextBlock Name="txtContent2" Text="2" />
                <TextBlock Name="txtContent3" Text="3" />
                <TextBlock Name="txtContent4" Text="4" />
                <TextBlock Name="txtContent5" Text="5" />
                <TextBlock Name="txtContent6" Text="6" />
                <TextBlock Name="txtContent7" Text="7" />
                <TextBlock Name="txtContent8" Text="8" />
            </DockPanel>
        </Viewbox>
    </ScrollViewer>
</Grid>

1 个答案:

答案 0 :(得分:0)

使用统一网格可以做类似的事情。

<UniformGrid Rows="1" Columns="8">
    <UniformGrid.Resources>
        <Style TargetType="TextBlock">
            <Setter Property="HorizontalAlignment" Value="Center"></Setter>
        </Style>
    </UniformGrid.Resources>
    <TextBlock Name="txtContent1" Text="1" />
    <TextBlock Name="txtContent2" Text="2" />
    <TextBlock Name="txtContent3" Text="3" />
    <TextBlock Name="txtContent4" Text="4" />
    <TextBlock Name="txtContent5" Text="5" />
    <TextBlock Name="txtContent6" Text="6" />
    <TextBlock Name="txtContent7" Text="7" />
    <TextBlock Name="txtContent8" Text="8" />
</UniformGrid>