Xaml Grid with TextBlock

本文关键字:TextBlock with Grid Xaml | 更新日期: 2023-09-27 17:50:13

大家下午好,

我有一个小问题,看起来很容易,但是我还没有解决办法。

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

我有一个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>
网格

在前面的图片中,我想在4个案例中的3个案例中使用文本。如果你有任何解决办法或变通办法,请告诉我。

Xaml Grid with TextBlock

看一下流程文档。它们允许您自定义文档中文本的布局方式。

右下角,(假设这是第四种情况下,你不想要文本),把一个BlockUIContainer在它。容器可以是空的或隐藏的,而不是折叠的,这样布局仍然适用。这将强制文本不侵占容器。

OK,我在这方面做了更多的工作,并根据Johnathon的响应(您的链接似乎不适用于winrt/windows phone),我检查了WP等效,我得到部分用于WP 8.0和RichTextBlockRichTextBlockOverflow在winrt。

这里有一个很好的教程。

我试图在我的第一个例子中实现它,这就是我所拥有的: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>

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

谢谢你的帮助