2010-03-04 195 views

回答

0

你需要看的RichTextBox和FlowDocument的,如果它是WPF和RichTextBox的,如果的Silverlight 4.0。

的Silverlight 4.0解決方案

 <RichTextBox TextWrapping="Wrap" IsReadOnly="False"> 
     <Paragraph> 
      More text here .. 
      <InlineUIContainer> 
       <Image Source="abc.jpg"/> 
      </InlineUIContainer> 
      more and more text here; 
      <LineBreak /> 
     </Paragraph> 
    </RichTextBox> 

WPF解決方案 -

<RichTextBox> 
<FlowDocument IsEnabled="true"> 
    <Paragraph> 
    Text text .. 
    <Button Margin="10,0,10,0" Content="A Button Float"/> 
    More text.. 
    </Paragraph> 
    <Paragraph TextAlignment="Center"> 
    <Image Source="abc.jpg"/> 
    text text.. 
    </Paragraph> 
    </FlowDocument> 
</RichTextBox> 
+0

任何在Silverlight 3.0中做這件事的方法是什麼? – abudker 2010-03-08 21:12:00

+2

這並不像HTML那樣將圖片包裹在圖片的周圍,而是將圖片與文字內嵌在一起,看起來很可笑。文本與巨大的空白。 – 2010-04-16 16:33:24

1

我解決這個問題而回。我知道的並不是一個好方法。這將工作,雖然它只是痛苦。

爲了簡化說明,爲什麼我們不假定圖像位於頁面的右上角,文本需要位於圖像的左下方。

首先將TextBlock和圖像放在一起。

計算TextBlock最底部的點和圖像最底部的點。雖然TextBlock的是你在一個時間到圖像下方的新創建的TextBlock移動一個字就越大。這將創建文本換行的假象(使用他們的首要利潤和實際高度。

leftText.Text = textToWrap; 
    bottomText.Text = string.Empty; 
    Stack<string> wordsToMove = new Stack<string>(); 
    double imageBottomPoint = image1.ActualHeight + image1.Margin.Top; 
    while ((leftText.ActualHeight + leftText.Margin.Top) > (imageBottomPoint + 14)) 
    { 
     int lastSpace = leftText.Text.LastIndexOf(' '); 
     string textToMove = leftText.Text.Substring(lastSpace).Trim(); 
     BlockedText.Text = leftText.Text.Remove(lastSpace); 
     wordsToMove.Push(textToMove + ' '); 
    } 
    StringBuilder sb = new StringBuilder(bottomText.Text); 
    while (wordsToMove.Count > 0) 
    { 
     sb.Append(wordsToMove.Pop()); 
    } 

    bottomText.Text = sb.ToString();