2

I wrote a panel similar to the built-in StackPanel. I works almost fine except for a slight problem:

Changing layout properties on children do not always cause the panel's MeasureOverride and ArrangeOverride to be called. They are always called when a child's Visibility property changes, but not when the Width and Height properties change.

I haven't yet managed to reproduce this behavior in a sample small enough to be appropriate for being included in a question on StackOverflow: But since it works fine in the trivial sample I made, I know I must do something avoidable in my actual panel.

So my question: In which circumstances does an element not invalidate its parents measure when changing size-related properties?

I tag this wpf also (I used Silverlight) to have a broader audience - I suspect this will apply to both xaml implementations equally.

John
  • 6,693
  • 3
  • 51
  • 90

2 Answers2

1

I figured what my mistake was and under which condition the panel's MeasureOverride is no longer called on certain changes for size-related properties.

My panel called Measure on children with the exact size the children should have, rather on the size of the panel.

A panel doesn't get it's MeasureOverride method called when children begin to desire more space than was told to them is available in the last Measure call - which makes sense.

Summary: The parameter for the Measure method you call on a child must denote the space the parent panel allots to all children, not just the one Measure is called on.

John
  • 6,693
  • 3
  • 51
  • 90
-1

You must make sure you call the base methods MeasureOverride.

    protected override Size MeasureOverride(Size availableSize)
    {
        // you must call this
        var throwaway = base.MeasureOverride(availableSize);

        // your code here

        return yourNewSize;
    }
Chui Tey
  • 5,436
  • 2
  • 35
  • 44
  • 1
    This has no effect either way: The sample works fine without this and my real-word panel still doesn't when I put it in. – John Dec 25 '13 at 15:58