wpfprotectedadornerlayerframeworkelement

Why is FrameworkElement.VisualChildrenCount protected?


Here's the background for my question:

  1. I would like to know if a particular System.Windows.Documents.AdornerLayer is empty or not.
  2. "OK, I'll make the check myAdornerLayer.VisualChildrenCount > 0."
  3. "Oh well, the property AdornerLayer.VisualChildrenCount is protected." (It overrides System.Windows.FrameworkElement.VisualChildrenCount which is also protected.)
  4. "Hm... That won't stop me. I'll just access myAdornerLayer.VisualChildrenCount via reflection."
  5. "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?


Solution

  • There is Visual Tree Helper class, that was made for this purpose..

    http://bing.com/search?q=visualTreeHelper