Search code examples
wpfrichtextboxclipboardimagesource

Saving source string of image in richtextbox after moving or pasting from clipboard


I'm working on richtextbox, which can handle images. I'm saving xaml content of richtextbox to database as string. Images are saved in the folder tree. And I have one problem:

When I insert image to richtextbox (in InlineUIContainer) all is working, saving and loading makes no problem. But when I drag image or cut and paste image again, source path of image is changed:

<Image>
    <Image.Source>
        <BitmapImage BaseUri="pack://payload:,,wpf1,/Xaml/Document.xaml" 
                     UriSource="./Image1.jpeg" CacheOption="OnLoad" />
    </Image.Source>
</Image>

original source was:

<Image Source="pack://siteoforigin:,,,/path_to_image/some_image.jpg" />

And therefore, when I save xaml again (still everything ok), I can't load images again, because in the xaml there are wrong paths to them (not ok :-)).

I searched for it, but I haven't found any solution. Could You help me please?


Solution

  • I found another way, I am saving it to the XAML package, Images are copied into it and everything works perfect.