为什么 FrameworkElement.VisualChildrenCount 受到保护?
这是我的问题的背景:
- 我想知道特定的 System.Windows.Documents.AdornerLayer 是否为空。
- “好的,我将检查
myAdornerLayer.VisualChildrenCount > 0
。” - “哦,好吧,
AdornerLayer.VisualChildrenCount
属性受到保护。” (它会覆盖同样受保护的System.Windows.FrameworkElement.VisualChildrenCount
。) - “嗯...这不会阻止我。我只需访问
myAdornerLayer.VisualChildrenCount
通过反思。” - “另一方面,这样做可能会产生某种不良的副作用。也许
VisualChildrenCount
受到保护是有原因的。我会询问 Stack Overflow”。
如果使用反射不是一个好主意,您是否有其他方法来确定 AdornerLayer
是否为空?
Here's the background for my question:
- I would like to know if a particular
System.Windows.Documents.AdornerLayer
is empty or not. - "OK, I'll make the check
myAdornerLayer.VisualChildrenCount > 0
." - "Oh well, the property
AdornerLayer.VisualChildrenCount
is protected." (It overridesSystem.Windows.FrameworkElement.VisualChildrenCount
which is also protected.) - "Hm... That won't stop me. I'll just access
myAdornerLayer.VisualChildrenCount
via reflection." - "On the other hand, maybe doing this will have some sort of bad side effect. Maybe
VisualChildrenCount
has been protected for a reason. I'll ask Stack Overflow".
If using reflection is a bad idea, do you have a suggestion for another way of finding out if an AdornerLayer
is empty or not?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有一个
Visual Tree Helper
类,就是为此目的而创建的。http:// /bing.com/search?q=visualTreeHelper
There is
Visual Tree Helper
class, that was made for this purpose..http://bing.com/search?q=visualTreeHelper