我将图像从URL插入到RichEditBox中,如下所示:

// Create a MemoryStream from uri, and insert into richeditbox
System.IO.Stream stream = await new HttpClient().GetStreamAsync("some url");
var memoryStream = new MemoryStream();
await stream.CopyToAsync(memoryStream);
memoryStream.Position = 0;
this.richEditBox.Document.Selection.InsertImage(40, 40, 0, Windows.UI.Text.VerticalCharacterAlignment.Baseline, "image", memoryStream.AsRandomAccessStream());


效果很好,但是按backspace时我无法删除(使用屏幕键盘)图像!

有人有想法么?

最佳答案

找到了!答案很简单-只需设置Selection.StartPosition

this.richEditBox.Document.Selection.StartPosition--;
this.richEditBox.Document.Selection.Delete(Windows.UI.Text.TextRangeUnit.Object, 1);


默认情况下,StartPositionEndPosition设置为Document.Selection,因此尝试删除只是不执行任何操作(因为未选择任何内容)。

注意:覆盖KeyDownRichEditBox事件并将以上内容添加到VirtualKey.Back按键中,以从屏幕键盘上获得所需的结果!

10-07 18:15