WPF:如何“取消绘制”自定义面板中的子项目?
基本上,我有一个面板,它根据 DependencyProperty (FooProperty) 绘制其子项。
如果 FooProperty 为 true,则孩子被安排;否则不予安排。第一次传递很好,但是当子项将其 FooProperty 从 true(绘制)更改为 false(不绘制)时,ArrangeOverride
方法会跳过它,并且子项仍保持绘制状态。
我想我需要某种方法来取消绘制它们,而不是跳过不应该绘制的孩子?
Basically, I have a panel that draws its children based upon a DependencyProperty (FooProperty).
If FooProperty is true, the child is arranged; otherwise, it is not arranged. The first passthrough is fine, but when a child changes it's FooProperty from true (draw) to false (don't draw) the ArrangeOverride
method skips it and the child remains drawn.
I figure instead of skipping the children that should not be drawn I need some way to undraw them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不会“取消绘制”子项目。发生的情况是,当某些东西触发
ArrangeOverride
传递时,您只需进行数学计算即可绘制/重画它。如果您想“伪跳过”该项目,则不能。一旦绘制完成,就必须重新绘制。但是,您始终可以使用 Rect(0, 0) 在 Point(0, 0) 处绘制它。基本上你把它装进了那里。
那么有没有办法“真正”取消绘制该项目呢?是的,以某种方式将其从InternalChildren集合中删除。您可以通过从可视树中删除该项目来完成此操作,或者如果您的面板是 ItemsSource 的主机面板,则可以从 ItemsSource 集合中删除该项目。
You don't "undraw" a child item. What happens is when something triggers the
ArrangeOverride
pass you simply do your math to draw/redraw it.If you want to "pseudo skip" the item, you can't. Once it is drawn it must be redrawn. But, you can always draw it at Point(0, 0) with a Rect(0, 0). Basically you're boxing it into nothing there.
So is there a way to "truly" undraw the item? Yes, remove it from the collection of InternalChildren somehow. You can do this by removing the item from the Visual Tree or if you're panel is the host panel to an ItemsSource you can remove that item from the ItemsSource collection.