2011-12-07 84 views
2

WP7包木窗的文本我有这样的代码:周围图像

<ScrollViewer x:Name="textScroller" Grid.Row="2"> 
     <Grid x:Name="ContentPanel" Margin="12,0,12,0" DataContext="{Binding}"> 
     <Image x:Name="ImageUrl" Source="{Binding ImageUrl}" Height="198" Width="150" Margin="10 10 10 10" FlowDirection="RightToLeft" HorizontalAlignment="Left" VerticalAlignment="Top" /> 
     <TextBlock x:Name="Content" Text="{Binding Content}" TextWrapping="Wrap" Style="{StaticResource PhoneTextNormalStyle}" Margin="0,41,24,-41" LineStackingStrategy="BlockLineHeight" MaxWidth="478" /> 
     </Grid> 
</ScrollViewer> 

形象在这段代码是文字块的背景,但我希望周围的imgae文本换行。它是否可行?我发现这similar question,有答案,它不是只有图像和文本块才有可能。这样对吗?我真的不能在图像中设置一些属性来设置文本不能在图像上?我应该如何更改我的代码? 感谢

编辑:现在这是我的页面的样子:

image is background

我想要的文字应该是在图像的右侧和下方的形象。

+0

从您的问题中不清楚您实际尝试达到的目标。你能提供一个模型吗?您可能正在寻找流布局,但目前手机上尚未提供该布局。根据您的具体要求,可能会有一种创建类似效果的方法。 –

+0

然后它与您链接的其他问题完全相同。 –

+0

可能重复的[WP7绕文本图像](http://stackoverflow.com/questions/5467040/wp7-wrap-text-around-image) –

回答

0

它是WP7 wrap text around imageSilverlight text around an image的副本,虽然这些问题还没有提出接受的答案。在Silverlight中没有这样的选项可以在图像周围自动换行。您可以使用WebBrowser组件或使用多个TextBlocks,方法是在向内存中的TextBlocks添加单词的同时测量文本的大小,并检查何时停止并切换到另一个TextBlock。我建议阅读一篇关于字体指标的文章 - MSDN - UI Frontiers: Font Metrics in Silverlight, Charles Petzold

编辑:硬编码的样本:

您可以使用下面的代码,你在一个硬编码的方式问什么。也许你可以编写一些代码,使它作为一个控件工作 - 通过检测矩形(或图像)旁边嵌套的TextBlock的高度来自动分割文本。

<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>