WPF 图片控件裁剪 [英] WPF Image control clipping

查看:47
本文介绍了WPF 图片控件裁剪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在自定义 ContentControl 中有一个 Image 控件,用于应用一些转换(通过 RenderTransform 进行缩放和转换).问题是图像比控件的区域大,如果我滚动或缩小它,它会像在原始视口中一样被剪裁.

I have an Image control inside a custom ContentControl that I use to apply some transforms (scaling and translating through the RenderTransform). The problem is that with images bigger than the control's area, if I scroll or zoom out it's all clipped as in the original viewport.

有没有办法强制图像完全自己绘制?(已经尝试将 ClipToBounds 设置为 false)

Is there a way to force the image to draw itself completely? (already tried to set ClipToBounds to false)

顺便说一下,如果我尝试将图像作为画布的背景,它可以正常工作.

By the way if I try to put an image as the background of a canvas it works correctly.

编辑,这里有一些细节.

Edit, here's some details.

我的控制:

public class CustomControl: ContentControl

设置阶段:

source = VisualTreeHelper.GetChild(this, 0) as FrameworkElement;
...
source.RenderTransform = this.transformGroup;

变换组由平移和缩放变换组成.

The transform group is made of a translation and a scale transform.

xaml 部分是这样的:

The xaml part is this:

<ui:CustomControl ClipToBounds="True">
    <Image
        Source="{Binding Path=BackgroundImage}"
        Stretch="None"
        ClipToBounds="False"/>
</ui:CustomControl>

推荐答案

我想我找到了解决方案.将我的图像包裹在画布中解决了这个问题,可能是因为画布大小的计算方式.

I think I found a solution. Wrapping my image inside a canvas solved the issue, probably due to the way canvas size is computed.

这篇关于WPF 图片控件裁剪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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