views:

636

answers:

0

I've got a project with some custom attached properties on a UserControl. When these properties change I want to trigger a layout pass because some part of the UserControl changes in response to this property changing.

In my user control, I've overridden MeasureOverride to update my shape, and this gets called when the page first loads, but when the attached dependency property is changed, and I call InvalidateMeasure on the parent panel containing the usercontrol in response to this, my user control's MeasureOverride never gets called.

However, if I resize the browser window, and a full layout pass happens, my MeasureOverride gets called as I'd expect.

In the simplest case, ignoring the custom property, if I directly call InvalidateMeasure on the parent grid, again, no MeasureOverride. However, if I directly call InvalidateMeasure on the usercontrol itself its MeasureOverride then gets called.

Is there something more I need to do on my UserControl to make this work, or am I just completely misunderstanding how the Measure/Arrange system should work? It looks like Silverlight is deciding for me which children of a panel need to get re-measured.

Update

I can get my desired behaviour if I have a custom panel to contain instances of my UserControl. In my MeasureOverride I have code like this:

foreach (UIElement e in this.Children)
{
    e.InvalidateMeasure();
    e.Measure(availableSize);
}

I don't believe the InvalidateMeasure should be necessary, but if I leave it out, Silverlight will call my Panel's MeasureOverride, and will execute my calls to e.Measure but will not pass those calls on to my UserControl's MeasureOverride. So I'd still like to know why it's behaving in this way.