问题
I have RichTextBox in WPF. I can copy and paste (drag&drop) images from Web Sites and from Windows Photo Viewer .
But If i try to copy image from directory
I'll can't paste in my RichTextBox
But if I create a special button to paste image from directory it will work:
private void Button_Click(object sender, RoutedEventArgs e)
{
string[] files = (string[])Clipboard.GetData(DataFormats.FileDrop);
if (files != null && files.Length > 0)
{
foreach (var file in files)
{
// Filter out non-image files
if (IsImageFile(file))
{
BitmapImage bitmap = new BitmapImage(new Uri(file));
Image image = new Image();
image.Source = bitmap;
var container = new InlineUIContainer(image, rtbEditor.CaretPosition);
rtbEditor.CaretPosition = container.ElementEnd;
e.Handled = true;
}
}
}
}
来源:https://stackoverflow.com/questions/55441272/how-copy-image-from-directory-folder-to-richtextbox-in-wpf