图片周围的Silverlight文字 [英] Silverlight text around an image

查看:70
本文介绍了图片周围的Silverlight文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将图像周围的文字换行,就像使用html float属性一样.有没有办法在Silverlight 3中完成此操作?

Im am trying to wrap text around an image as one would use the html float property. Is there a way to acomplish this in silverlight 3?

谢谢

推荐答案

我不久前解决了这个问题.我没有真正知道的好方法.尽管会很痛苦,但这仍然可以工作.

I tackled this issue a while back. There is not really a good way that I know of. This will work though it's just painful.

为了简化说明,我们为什么不假设图像位于页面的右上角,而文本则必须位于图像的左侧和下方.

In order to simplify the explanation why don't we assume that the image is in the upper right corner of the page and the text needs to be to the left and below the image.

首先将TextBlock和Image并排放置.

Start by placing the TextBlock and the Image side-by-side.

计算TextBlock的最底点和图像的最底点. (使用其上边距和实际高度.

Calculate the bottom most point of the TextBlock and the bottom most point of the image. (Use their top margins and actual heights.

虽然TextBlock较大,但您一次将一个单词移动到图像下方的新创建的TextBlock中.这会产生环绕文本的错觉.

While the TextBlock is the larger you move a word at a time into a newly created TextBlock below the image. This creates the illusion of wrapping text.

    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();

这篇关于图片周围的Silverlight文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆