姬長信(Redy)

silverlight-以编程方式将图像添加到RichTextBo…


尝试通过流将图像以编程方式添加到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属性中.