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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With