尝试从流中以编程方式将图像添加到 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 anyUIElement
objects that are present in the content.
关于silverlight - 以编程方式将图像添加到 RichTextBox 不会显示在 Xaml 属性中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2530053/