WPF:自定义 StackPanel 中的 ArrangeOverride
我想制作一个自定义面板来(除其他外)在所有子项之间插入间距。从Panel 继承似乎非常复杂,而且也许没有必要。我想要的是接近 StackPanel 所以我想我可以继承 StackPanel 并修改 ArrangeOverride 和 MeasureOverride 以获得我想要的。 我从 Reflector 获得了这些的实现,但立即注意到一个属性根本无法从继承类访问,即 IsScrolling(和字段 _scrollData)。我的问题是我是否可以跳过这个或者是否有其他方法可以实现相同的行为?我不确定我是否需要滚动这个自定义面板,但有一天我可能会这样做,但我不想把自己逼到角落......
I want to make a custom Panel to (amongst other things) insert spacing between all children. To inherit from Panel seemed very complicated and perhaps unnecessary. What I want is close to StackPanel so I figured I could inherit from StackPanel and modify the ArrangeOverride and MeasureOverride to get what I want.
I got the implementation of these from Reflector but immediately noticed that one property was not accessible at all from a inherited class, namely IsScrolling (and the field _scrollData). My question is if I can skip this or if there is any other way of implementing identical behaviour? Im not sure I will need scrolling for this custom panel but I may do some day and I dont want to paint myself into a corner...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想要的只是容器内的所有元素都自动包含边距定义,那么您最好只创建一个实现该功能的自定义行为。
要创建自定义行为,只需实现
Behavior
。这是不言自明的,但如果您不知道如何做,请询问。if all you want is just that all elements inside a container would automatically contain margin definitions, you're much better off just creating a custom behavior that implements that functionality.
to create a custom behavior, just implement
Behavior<Panel>
. It's rather self-explanatory, but if you don't know how then ask.