粘贴或移动图像后将图像来源保留在RichTextBox中

问题描述 投票:0回答:0

我正在使用可以包含图像的 RichTextBox。我用

OpenFileDialog
导入它们,然后放入
InlineUIContainer

显示出来,xaml代码如下

<Paragraph>
    <Image Source="file://C:/Path/Test.png" Stretch="Fill" Width="200" Height="100" />
</Paragraph>

我可以将我的xaml文档保存在数据库中,关闭它并再次打开它没有任何问题,图像仍然会显示。

但是,如果我从文档中移动图像并复制并粘贴它,我的 xaml 代码将变为如下:

<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>

它现在包含在 BlockUIContainer 中,我不想将其用于显示目的,但这不是我更大的问题,因为我丢失了 ImageSource,因此无法再次显示它们。

您有任何解决方案来防止这种行为吗?

我尝试使用

DataObject.AddCopyingHandler
et
DataObject.AddPastingHandler
拦截复制和粘贴事件,但无法获得所需的结果。

我还发现了这个问题Saving source string of image in richtextbox after moving or Pasting from Clipboard有类似的问题,但我不明白“将其保存到XAML包”是什么意思。

c# wpf richtextbox
© www.soinside.com 2019 - 2024. All rights reserved.