Adding an image to a RichTextBox programmatically does not appear in the Xaml property

An attempt to add an image to a RichTextBox programmatically from a stream. The image is displayed in the text box, however, when reading the property Xamlfor the image there is no markup.

    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);
    }

What is the correct way to insert an image into a RichTextBox at runtime so that it is stored in the data store? In the property Xaml.

+3
source share
2 answers

He cannot (at least for the time being). The RichTextBox Overview help file says:

XAML, Xaml UIElement , .

+2

, XAML . , RTB.Blocks () Inlines. InlineUIContainer .

+2

Source: https://habr.com/ru/post/1738788/


All Articles