当父 UIElement 的 RenderTransform 更改时,如何调用 OnRender?
我有一个 System.Windows.Controls.Image 派生类,需要通知父 UIElement 的 RenderTransform 已更改(假设发生了缩放)。我希望能够限制内存中保存的内容,这样当只有一小部分可见时,我就不会在内存中保留巨大的图像,并且当图像缩小时降低分辨率。有没有办法强制在我的图像上调用 OnRender?我知道 AffectsRender 可以在父级的 RenderTransformProperty 上设置,但这不会渗透到我的图像中......有什么想法吗?
I have a System.Windows.Controls.Image derived class that needs notification that the parent UIElement's RenderTransform has changed (say a zoom occurred). I want to be able to limit whats kept in memory so that I'm not keeping a huge image in memory when only a small portion is visible, as well as decrease the resolution when the image is zoomed out. Is there a way to force OnRender to be called on my Image? I know AffectsRender can be set on the parent's RenderTransformProperty, but that doesn't trickle down to my Image...any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对我来说,这感觉有点麻烦,但您可以在图像上引入一个新的依赖属性,该属性的 AffectsRender = true。 DP 应该是 object 类型,并且您应该将其绑定到其父级的 RenderTransform。因此,当父级的 RenderTransform 发生变化时,子级的 DP 将使子级重新渲染自身。
It feels a bit of a hack to me, but you can introduce a new Dependency Property on your image that has AffectsRender = true. The DP should be of type object, and you should Bind it to the RenderTransform of its parent. Thus, when RenderTransform of the parent changes, the child's DP would make the child re-render itself.