简体   繁体   English

ContentControl中的渲染顺序-WPF

[英]Rendering order in ContentControl - WPF

There is something that I don't understand regarding ContentControl: I've a class that inherits from ContentControl, and it overrides the OnRender method. 关于ContentControl,我有些不了解:我有一个从ContentControl继承的类,它覆盖了OnRender方法。 And although I don't call base.OnRender(drawingContext) still the content is being rendered... 而且尽管我不叫 base.OnRender(drawingContext)仍然在渲染内容...

How come? 怎么会?

What am I missing? 我想念什么?

Thanks, Eden 谢谢,伊甸园

Only primitive controls that directly have to draw on the device context, like Border or TextBlock override OnRender to do their jobs. 只有直接必须在设备上下文上进行绘制的原始控件(如BorderTextBlock才会覆盖OnRender来执行其工作。 Since most of controls are just a combination of those primitives, they don't draw directly. 由于大多数控件只是这些原语的组合,因此它们不能直接绘制。 Instead, they're measuring and arranging their children so that they are at the good position and size. 取而代之的是,他们正在衡量和安排孩子,以使他们处于良好的位置和身材。

What you need to override are the methods MeasureOverride and ArrangeOverride . 您需要重写的是MeasureOverrideArrangeOverride方法。

That being said, if you don't want to render anything, it's better to set the Visibility of the control to Collapsed . 话虽如此,如果您不想渲染任何东西,最好将控件的Visibility设置为Collapsed

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM