2011-12-07 142 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>