1

我创建了用于显示新闻的控件。每个新的都包含文本和图像。在这里,我找到了 RichTextBox 的示例:

<RichTextBox VerticalAlignment="Top">
    <Paragraph
        TextAlignment="Left">
        <InlineUIContainer>
            <InlineUIContainer.Child>
                <Rectangle
                    Width="50"
                    Height="50"
                    Fill="Red" />
            </InlineUIContainer.Child>
        </InlineUIContainer>
        <InlineUIContainer>
            <Border>
                <TextBlock
                    Padding="0"
                    Width="370"
                    Margin="0,0,0,-5"
                    TextWrapping="Wrap"
                    Text="First part of text that fits to the right of the image before the other part wraps to">
                </TextBlock>
            </Border>
        </InlineUIContainer>
        <Run
            Text="the next line. This part of the text is already below the image." />
    </Paragraph>
</RichTextBox>

但是有问题:new 包含一个文本块(<p>...</p>),我不能从示例中动态划分文本为 2 个文本块。我该如何解决我的问题?谢谢你。 UPD:这是我的控件的标记:

<UserControl>
    <Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}" Margin="0,0,0,-100">     
        <TextBlock x:Name="tblNewName" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="460" Height="50" TextAlignment="Center" FontFamily="Mangal"/>
        <Grid Height="105" Width="441">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="97*"/>
                <ColumnDefinition Width="344*"/>
            </Grid.ColumnDefinitions>
            <Image x:Name="imgThumbnail" Grid.ColumnSpan="2" HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="100"/>
            <TextBlock Grid.Column="1" x:Name="tblNewTeaser" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="460" Height="50" TextAlignment="Center" FontFamily="Mangal"/>
        </Grid>
    </Grid>
</UserControl>

我需要在图像周围的文本块中包装文本。

4

1 回答 1

1

你想展示什么数据?这是 HTML 吗?给我一个新闻数据的例子。

更新: 你需要的是:

 public class NewsItem
    {
        public string ImageUri { get; set; }
        public IEnumerable<string> Paragraphs { get; set; }        
    }

<DataTemplate x:Key="newsTemplate">
            <Grid Height="105" Width="441">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="97*"/>
                    <ColumnDefinition Width="344*"/>
                </Grid.ColumnDefinitions>
                <Image Grid.ColumnSpan="2" HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="100"/>
                <ListBox Grid.Column="1" ItemsSource="{Binding Paragraphs}"></ListBox>
            </Grid>
        </DataTemplate>

<Grid x:Name="colorPlace" Grid.Row="1" Margin="12,0,12,0"/>        
<ListBox Grid.Row="1" Name="newList" ItemTemplate="{StaticResource newsTemplate}">

</ListBox>
</Grid>

最后:

var data = new List<NewsItem>
                       {
                           new NewsItem
                           {
                               ImageUri = String.Empty,
                               Paragraphs = new[]
                                            {
                                                "blablabla",
                                                "blablabla",
                                                "blablabla"
                                            }
                           },
                           new NewsItem
                           {
                               ImageUri = String.Empty,
                               Paragraphs = new[]
                                            {
                                                "blablabla",
                                                "blablabla",
                                                "blablabla"
                                            }
                           }
                       };
于 2013-07-13T20:28:20.643 回答