WPF裁剪问题
我有一个用户控件,它有一个二次图像作为子项。该Image 位于UserControl 的底部,其中一半被剪裁(例如Control 的高度为400,Image 的高度为200,并且设置为y=300)。
现在,当我旋转图像时,它仍然像第一次一样被剪裁。就像旋转 90 度时,我突然得到一个只有 100 像素宽的图像。
看起来由于 UserControl 的边界而进行的原始剪辑将永远应用。
我该如何解决这个问题?我希望我的问题可以理解;)
I have a UserControl which has a quadratic Image as a Child. This Image is at the bottom of the UserControl, and half of it is clipped (e.g. the Control's Height is 400, Image's height is 200 and it is set to y=300).
Now, When I rotate the Image, it is still clipped like the way it was first. Like when rotating around 90 degrees, I suddenly have an Image which is only 100px wide.
It seems like the original clipping which was made because of the bounds of the UserControl, are applied forever.
How do I solve this problem? I hope I explained my problem understandable ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你如何旋转图像?如果您使用 RenderTransform 进行旋转,则WPF 不会重新渲染屏幕上已显示的内容 - 它只是旋转像素。
相反,使用 LayoutTransform 旋转图像;这会强制 WPF 在给定其占据的新区域的情况下重新呈现控件,这应该会消除您看到的剪辑。
How are you rotating the image? If you are rotating using a RenderTransform, then WPF does not re-render what was already displayed on the screen - it simply rotates the pixels.
Instead, rotate the image using a LayoutTransform; this forces WPF to re-render the control given the new area it occupies, which should eliminate the clipping you see.
您还可以在应用渲染转换后调用
InvalidateMeasure()
。You can also call
InvalidateMeasure()
after applying render transform.