2012-05-04 40 views
8

在XAML中可以做些什麼,比如ffloat:左圖爲CSS中的圖像。我需要這樣創造的東西:如何在XAML中「漂浮」圖像(Windows 8 Metro)

enter image description here

與可變圖像尺寸和文本長度。

編輯:圖片周圍的文字經是不是在我的情況下,靜態的,它是在返回的TextBlock元素的列表(運行)的C#代碼

回答

1

This question似乎建立在問類似的東西到你想要的。答案here應該證明你想要的是一個解決方案。

答案的總結,使用FlowDocument像下面的例子:

<FlowDocument> 
    <Paragraph> 
     <Floater HorizontalAlignment="Left"> 
      <BlockUIContainer> 
       <Image Source="/FlowDocumentTest;component/dog.png" Width="100" /> 
      </BlockUIContainer> 
     </Floater> 
     Here is where the text goes to wrap around the image. 
    </Paragraph> 
</FlowDocument> 

更新

至於你的問題的狀態,您現在正在使用一些C#代碼來生成的TextBlock /運行元素,都可以是段落對象的子元素。所以,簡單地命名Paragraph像這樣:

<FlowDocument> 
    <Paragraph x:Name="textPara"> 
     <Floater HorizontalAlignment="Left"> 
      <BlockUIContainer> 
       <Image Source="/FlowDocumentTest;component/dog.png" Width="100" /> 
      </BlockUIContainer> 
     </Floater> 
    </Paragraph> 
</FlowDocument> 

然後在C#中,添加產生TextBlock S或Run s到textPara的Inlines財產,即

var runToInsert = new Run("Some text to display"); 
textPara.Inlines.InsertAfter(textPara.Inlines.FirstInline, runToInsert); 
+0

我編輯的問題。 Text on不是靜態的,而是一堆文本框。我將它們插入到StackPanel中,但是如何將它們插入到此? –

+0

更新了我的答案,以及如何動態添加內容。 – Lukazoid

+0

我不認爲段落中的Paragprah是有效的。編譯器agress –

3

使用Silverlight 4,你會使用實現這個一個RichTextBox

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

它看起來像在Win8地鐵有一個RichTextBox,還有一個InlineUIContainer,所以像上面的東西應該工作!

+0

你如何在C#中創建這個?我有一個TextBlocks列表(帶有運行),所以我想我可以將firts一個轉換爲這個,我會好的 –

+0

似乎並不工作http://dl.dropbox.com/u/73642/flow.png –

相關問題