silverlight - 以编程方式将图像添加到 RichTextBox 不会显示在 Xaml 属性中

标签 silverlight silverlight-4.0 richtextbox

尝试从流中以编程方式将图像添加到 RichTextBox。图像显示在文本框中,但是在读取 Xaml 属性时没有图像标记。

    private void richTextBox3_Drop(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(DataFormats.FileDrop))
        {
            FileInfo[] files = (FileInfo[])e.Data.GetData(DataFormats.FileDrop);
            using (Stream s = files[0].OpenRead())
            {
                InlineUIContainer container = new InlineUIContainer();
                BitmapImage bmp = new BitmapImage();
                bmp.SetSource(s);
                Image img = new Image();
                img.SetValue(Image.SourceProperty, bmp);
                container.Child = img;

                richTextBox3.Selection.Insert(container);
            }
        }
    }

    private void Button_Click_1(object sender, RoutedEventArgs e)
    {
        // this doesn't have the markup from the inserted image
        System.Windows.MessageBox.Show(richTextBox3.Xaml);
    }

在运行时将图像插入 RichTextBox 以便将其保存到数据存储中的正确方法是什么?在 Xaml 属性中。

最佳答案

它不能(至少目前)。 RichTextBox Overview帮助文件说:

The XAML string returned by the Xaml property will not include any UIElement objects that are present in the content.

关于silverlight - 以编程方式将图像添加到 RichTextBox 不会显示在 Xaml 属性中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2530053/

相关文章:

silverlight-4.0 - 如何使用 caliburn.micro 绑定(bind)到命令属性?

wpf - Silverlight 4 中的像素字体

c# - RichTextBox 项目符号缩进(.NET 窗体)

sharepoint - 在 Sharepoint 2013 中使用富文本框

Silverlight 5 向后兼容性

asp.net-mvc - ASP.NET MVC 加 Silverlight

silverlight - 如何在 Silverlight 4 中使换行文本与按钮内嵌?

wpf - 仅在 RichTextBox 中为选择添加下划线

asp.net-mvc - 用于 Web 开发的 Silverlight 或 MVC

c# - 页眉和页脚布局