二传布局系统WPF和Silverlight布局、二传、系统、Silverlight

2023-09-03 00:35:04 作者:年少的时光掌心纹路

很多时候,我已经看到,code。在的MeasureOverride ArrangeOverride 是相同的节选调用措施,安排相应的方法和有点像动漫等各个项目额外的逻辑 ArrangeOverride

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?

我缺少什么?

推荐答案

是的,你缺少两者之间的细微差别。

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

的MeasureOverride ,父的要求的孩子,它希望有多大是。

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

ArrangeOverride ,父的通知的孩子,它实际上多少空间了,并在那里被放置

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.

要穿上这一点来看,对WPF的关键点之一是可扩展的用户界面。就像老板/员工以上的情况,需要父/子控制的需要,保持平衡。仅仅因为一个子控件的请求的具有一定规模,这并不意味着父控件有空间给,使需要传达给孩子。 OTOH,与显示器的规模日益扩大,你的孩子可能会得到相当多的地产比它真正需要。

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.