Search code examples
wpfpanelchildrenmeasureoverridearrangeoverride

Panel.Children vs Panel.InternalChildren -- What's the difference?


According to MSDN - Panel.InternalChildren Property:

Classes that are derived from Panel should use this property, instead of the Children property, for internal overrides such as MeasureCore and ArrangeCore.


So, this is really a 2 part question:

  1. If I create a Panel of my own, FooPanel, which derives from Panel, I can't seem to override MeasureCore or ArrangeCore. I'm not sure why that statement is even there. I can, however, override MeasureOverride and ArrangeOverride. So, I wonder if I still need to use the InternalChildren property for these 2 methods.

  2. What is the real difference between the Children property and the InternalChildren property?


Solution

    1. You would override MeasureOverride and ArrangeOverride, that must be a mistake in the documentation, or intended for internal Microsoft employees. The MeasureCore and ArrangeCore are sealed by FrameworkElement, so you can't override them.

    2. The Children property is public and simply calls InternalChildren, which is protected. So either is probably safe, since Children would get inlined.

    MSDN says otherwise ( http://msdn.microsoft.com/en-us/library/ms754152.aspx) but the documentation is wrong. (use reflector to see that the implementation of Children simply calls InternalChildren)