So to paste Image In Rich Edit Box for Windows 10, Windows Phone 8.1 First Drag and Drop a "RichEditBox". Like this:
- <RichEditBox x:Name="rtbox"
- Width="500"
- HorizontalAlignment="Center"
- VerticalAlignment="Center"
- KeyDown="rtKeydown" />
Now Double Click the "rtKeydown" event .so to achieve our task we need get the content from Clipboard.and read the image content from DataPackage of clipboard like this:
- private async void rtKeydown(object sender, KeyRoutedEventArgs e)
- {
- if (e.Key == Windows.System.VirtualKey.V && e.Key == Windows.System.VirtualKey.Control)
- {
- var dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();
- if (dataPackageView.Contains(StandardDataFormats.Bitmap))
- {
- IRandomAccessStreamReference imageReceived = null;
- try
- {
- imageReceived = await dataPackageView.GetBitmapAsync();
- }
- catch (Exception ex)
- {}
- if (imageReceived != null)
- {
- using(var imageStream = await imageReceived.OpenReadAsync())
- {
- var bitmapImage = new BitmapImage();
- bitmapImage.SetSource(imageStream);
- rtbox.Document.Selection.InsertImage((int) bitmapImage.PixelWidth, (int) bitmapImage.PixelHeight, 0, Windows.UI.Text.VerticalCharacterAlignment.Baseline, "Image", imageStream);
- e.Handled = true;
- Clipboard.Clear();
- }
- }
- }
- else
- {
-
- }
- }
- }
Now Run the App.its completed. output will be like this:
Copying the image from Browser.
![Browser]()
Pasting in RichEditBox.
![RichEditBox]()
Please comment below for any doubts.