如何在 RichEditBox 中插入的图像中显示调整大小的装饰器? [英] How to display resizing adorner in an image inserted in a RichEditBox?

查看:31
本文介绍了如何在 RichEditBox 中插入的图像中显示调整大小的装饰器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向插入到 UWP 应用程序 RichEditBox 中的图像显示调整大小的装饰器.

I'm trying to display resizing adorners to an image inserted in a RichEditBox in a UWP application.

到目前为止,我可以使用以下代码插入图像:

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:

我最初尝试调整我在这个问题中为 WPF 找到的解决方案,但不幸的是 UWP 没有装饰品.然后,我尝试调整我为 Winforms 找到的解决方案,但这依赖于对 RichTextBox 控件进行子类化并覆盖其 WndProc 方法,这在 UWP 中也是不可能的.

I initially tried to adapt a solution that I found for WPF in this question, but unfortunately UWP has no concept of adorners. 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.

那么,我如何才能在 UWP 中完成我上面描述的内容?

So, how can I acomplish what I described above in UWP?

推荐答案

将调整大小的装饰器显示为插入到 RichEditBox 中的图像UWP 应用.

Display resizing adorners to an image inserted in a RichEditBox in a UWP application.

UWP中没有可以调整RichEditBox中插入图片大小的api,需要自定义一个控件,将图片包裹在里面.通过拖动控件来调整图像大小.或者在 wpf 或 winform 中编程,然后使用 desktop桥 将其转换为 UWP 应用.

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. By dragging the control to resize image. Or programming in wpf or winform and then use desktop bridge to convert it to UWP app.

这篇关于如何在 RichEditBox 中插入的图像中显示调整大小的装饰器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆