【发布时间】:2012-05-04 08:45:51
【问题描述】:
是否可以在 XAML 中为 CSS 中的图像执行类似 ffloat:left 的操作。我需要创建这样的东西:
具有可变的图像尺寸和文本长度。
编辑:在我的情况下,图像周围的文本扭曲不是静态的,它是在 C# 代码中创建的,返回一个 TextBlock 元素列表(带有运行)
【问题讨论】:
标签: c# xaml windows-8 windows-runtime winrt-xaml
是否可以在 XAML 中为 CSS 中的图像执行类似 ffloat:left 的操作。我需要创建这样的东西:
具有可变的图像尺寸和文本长度。
编辑:在我的情况下,图像周围的文本扭曲不是静态的,它是在 C# 代码中创建的,返回一个 TextBlock 元素列表(带有运行)
【问题讨论】:
标签: c# xaml windows-8 windows-runtime winrt-xaml
使用 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 Metro 有一个RichTextBox,也有一个InlineUIContainer,所以上面的方法应该可以工作!
【讨论】:
解决方案似乎是使用本演示文稿中描述的 RichTextBlockOverflow 和 OverflowContentTarget:http://video.ch9.ms/build/2011/slides/APP-914T_Street.pptx
【讨论】:
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/Run 元素,它们都可以是 Paragraph 对象的子级。因此,只需将您的 Paragraph 命名为:
<FlowDocument>
<Paragraph x:Name="textPara">
<Floater HorizontalAlignment="Left">
<BlockUIContainer>
<Image Source="/FlowDocumentTest;component/dog.png" Width="100" />
</BlockUIContainer>
</Floater>
</Paragraph>
</FlowDocument>
然后在C#中,将你生成的TextBlocks 或Runs 添加到textPara 的Inlines 属性中,即
var runToInsert = new Run("Some text to display");
textPara.Inlines.InsertAfter(textPara.Inlines.FirstInline, runToInsert);
【讨论】: