简体   繁体   English

如何在 RichEditBox 中插入的图像中显示调整大小的装饰器?

[英]How to display resizing adorner in an image inserted in a RichEditBox?

I'm trying to display resizing adorners to an image inserted in a RichEditBox in a UWP application.我正在尝试将调整大小的装饰器显示为插入到 UWP 应用程序的 RichEditBox 中的图像。

So far I can insert an image using the following code:到目前为止,我可以使用以下代码插入图像:

        private async void InsertImage()
        {
            var picker = new FileOpenPicker { SuggestedStartLocation = PickerLocationId.PicturesLibrary };
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".png");
            var files = await picker.PickMultipleFilesAsync();

            if (files.All(file => file != null))
            {
                foreach (var file in files)
                {
                    using (var stream = await file.OpenAsync(FileAccessMode.Read))
                    {
                        var image = new BitmapImage();
                        await image.SetSourceAsync(stream);
                        textEditor.Document.Selection.InsertImage(image.PixelWidth / 2, image.PixelHeight / 2, 0, VerticalCharacterAlignment.Baseline, 
                                                                  file.DisplayName, stream);
                    }
                }
            }
        }

Once the image is inserted I can resize it, but when I click on the image the cursor doesn't change and the resizing adorners don't display at all, making the resizing task not very user friendly.插入图像后,我可以调整它的大小,但是当我单击图像时,光标不会改变,并且根本不显示调整大小的装饰器,这使得调整大小任务对用户不是很友好。 In other words, what I want is shown in the image below:换句话说,我想要的如下图所示:

调整装饰器的大小

I initially tried to adapt a solution that I found for WPF in this question , but unfortunately UWP has no concept of adorners.我最初尝试调整我在这个问题中为 WPF 找到的解决方案,但不幸的是 UWP 没有装饰器的概念。 Then, I tried to adapt a solution that I found for Winforms, but that relies on subclassing the RichTextBox control and override its WndProc method, and that also is not possible in UWP.然后,我尝试调整我为 Winforms 找到的解决方案,但它依赖于 RichTextBox 控件的子类化并覆盖其WndProc方法,这在 UWP 中也是不可能的。

So, how can I acomplish what I described above in UWP?那么,我如何才能在 UWP 中完成我上面描述的内容?

Display resizing adorners to an image inserted in a RichEditBox in a UWP application.为插入到 UWP 应用程序 RichEditBox 中的图像显示调整大小的装饰器。

There is no api that can resize the image inserted in the RichEditBox in UWP, you need to customize a control and wrap the image inside it. UWP中没有可以调整RichEditBox中插入图片大小的api,需要自定义一个控件,将图片包裹在里面。 By dragging the control to resize image.通过拖动控件来调整图像大小。 Or programming in wpf or winform and then use desktop bridge to convert it to UWP app.或者在 wpf 或 winform 中编程,然后使用桌面桥将其转换为 UWP 应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM