Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two Pass Layout system in WPF and Silverlight

Many times I have seen that the code in MeasureOverride and ArrangeOverride is same excepts calling measure and arrange in respective methods and a bit of additional logic like animation etc for each item in ArrangeOverride.

Would it not be simple if you just have a method to pass your logic of measuring at one place and layout system remembers that and have an event when each item is about to add and you apply the additional logic of animation etc?

Am I missing anything?

like image 841
user510471 Avatar asked Nov 17 '10 07:11

user510471


1 Answers

Yep, you are missing the subtle difference between the two.

In MeasureOverride, the parent asks the child how big it wants to be.

In ArrangeOverride, the parent tells the child how much space it actually has and where it is being placed.

It is like budget or review time at your work: your boss asks you how much money you want, then laughs and tells you how much you will actually get and when. Like the child control, you then have to do your best with what you are given.

To put a little perspective on this, one of the key points of WPF is scalable UI. Much like the boss/employee scenario above, the needs of the parent/child control need to be kept in balance. Just because a child control requests a certain size, that doesn't mean the parent control has that space to give, so that needs to be communicated to the child. OTOH, with the increasing size of monitors your child may end up with considerably more real estate than what it really needs.

like image 71
slugster Avatar answered Sep 29 '22 01:09

slugster