I'm using a RichTextBox thant can contains images. I import them with an OpenFileDialog
and put then into an InlineUIContainer
.
It is displayed and the xaml code is as follows.
<Paragraph>
<Image Source="file://C:/Path/Test.png" Stretch="Fill" Width="200" Height="100" />
</Paragraph>
I can save my xaml document in the database, close it and open it again without any problems, the image will still be displayed.
But if I ever move the image from within the document oc copy and paste it, my xaml code becomes as follow :
<BlockUIContainer>
<Image Stretch="Fill" Width="200" Height="100">
<Image.Source>
<BitmapImage BaseUri="pack://payload:,,wpf3,/Xaml/Document.xaml" UriSource="./Image1.png" CacheOption="OnLoad" />
</Image.Source>
</Image>
</BlockUIContainer>
It is now contained within a BlockUIContainer, which I don't want for display purposes, but it's not my bigger problem, because I lost the ImageSource, thus not able to display them again.
Do you have any solutions to prevent this behavior ?
I tried to intercept the Copy and Paste event with DataObject.AddCopyingHandler
et DataObject.AddPastingHandler
, but couldn't manage to get the desired result.
I also found this question Saving source string of image in richtextbox after moving or pasting from clipboard with a similar problem but I don't understand what is meant by "saving it to the XAML Package".