Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
709 views
in Technique[技术] by (71.8m points)

.net - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...