带有TextBlock的Xaml Grid

时间:2015-05-21 12:52:33

标签: c# wpf xaml windows-runtime windows-phone-8.1

大家下午好,

我有一个看似简单的小问题但是我所拥有的还没有解决方案。

我试图提供信息,使解决方案尽可能简单易懂:

我有一个包含2列和2行的网格,我想在4个案例中的3个中添加一个文本。

这就是我现在所拥有的:

<Grid VerticalAlignment="Center" HorizontalAlignment="Center">
    <Grid.RowDefinitions>
        <RowDefinition Height="100" />
        <RowDefinition Height="100" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="100" />
        <ColumnDefinition Width="100" />
    </Grid.ColumnDefinitions>

    <TextBlock Grid.RowSpan="2" Grid.ColumnSpan="2" Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
               In nec pharetra leo. Donec quis faucibus elit. 
               Praesent vel risus libero. 
               Curabitur neque urna, pulvinar eu imperdiet feugiat, molestie sit amet orci.
               Sed purus est, vehicula in tortor et, blandit dictum dolor.
               Etiam fringilla non purus sed vulputate.
               Maecenas id sagittis lorem, et ultricies massa.
               Nullam bibendum dolor vel ipsum cursus congue. 
               Quisque ac molestie mi. Etiam ac ex quam. 
               Fusce tempus eros nec ultrices condimentum. 
               Proin malesuada sem id suscipit vehicula. 
               Integer risus nibh, ultricies eget rhoncus sit amet, mattis id quam. 
               Mauris ac augue sit amet nulla scelerisque sollicitudin. 
               Duis ac nulla sem. Sed elementum ac tortor vel finibus.
               Ut magna diam, efficitur a cursus a, commodo ut risus.
               Mauris elementum nulla tortor, a egestas ipsum luctus et.
               Fusce quis dui purus.
               Donec aliquam fermentum diam vitae vulputate. 
               Donec at quam condimentum nunc efficitur consequat.
               Mauris id porttitor tortor.
               Nunc odio diam, ullamcorper id neque non, molestie volutpat elit. 
               Ut rutrum dignissim ex, et hendrerit massa tincidunt eget. "
               TextWrapping="Wrap"/>

</Grid>

Grid

在上图中,我希望在4个案例中有3个案文。 如果您有任何解决方案或解决方法,请告诉我。

2 个答案:

答案 0 :(得分:0)

看看Flow Documents。它们允许您自定义文档中文本的布局方式。

右下角(假设这是你不想要文本的第四种情况)在其中放置BlockUIContainer。容器可以是空的或隐藏的,而不是折叠的,因此仍然应用布局。这会强制文本不会侵占容器。

答案 1 :(得分:0)

好的,我的工作更多,基于Johnathon的回复(你的链接似乎不适用于winrt / windows手机),我检查了WP等效,我得到WP的8.0 Section 在winrt中使用 RichTextBlockOverflow RichTextBlock

Here is a great tutorial for that.

我试图在我的第一个例子中实现它,这就是我所拥有的:Grid v2

这是代码:

<Grid VerticalAlignment="Center" HorizontalAlignment="Center">
    <Grid.RowDefinitions>
        <RowDefinition Height="200" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>

    <RichTextBlock 
        x:Name="RtbSource"
        Grid.ColumnSpan="2"
        OverflowContentTarget="{Binding ElementName=RtboFirst}"
        TextTrimming="WordEllipsis" 
        TextWrapping="WrapWholeWords">
        <Paragraph>
            <Run Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
               In nec pharetra leo. Donec quis faucibus elit. 
               Praesent vel risus libero. 
               Curabitur neque urna, pulvinar eu imperdiet feugiat, molestie sit amet orci.
               Sed purus est, vehicula in tortor et, blandit dictum dolor.
               Etiam fringilla non purus sed vulputate.
               Maecenas id sagittis lorem, et ultricies massa.
               Nullam bibendum dolor vel ipsum cursus congue. 
               Quisque ac molestie mi. Etiam ac ex quam. 
               Fusce tempus eros nec ultrices condimentum. 
               Proin malesuada sem id suscipit vehicula. 
               Integer risus nibh, ultricies eget rhoncus sit amet, mattis id quam. 
               Mauris ac augue sit amet nulla scelerisque sollicitudin. 
               Duis ac nulla sem. Sed elementum ac tortor vel finibus.
               Ut magna diam, efficitur a cursus a, commodo ut risus.
               Mauris elementum nulla tortor, a egestas ipsum luctus et.
               Fusce quis dui purus.
               Donec aliquam fermentum diam vitae vulputate. 
               Donec at quam condimentum nunc efficitur consequat.
               Mauris id porttitor tortor.
               Nunc odio diam, ullamcorper id neque non, molestie volutpat elit. 
               Ut rutrum dignissim ex, et hendrerit massa tincidunt eget. "/>
        </Paragraph>

    </RichTextBlock>
    <RichTextBlockOverflow 
        x:Name="RtboFirst"
        Grid.Row="1" />

</Grid>

我会尝试在我的项目中实现它,我会上传任何重要信息。

感谢您的帮助。