In WPF how can I get the rendered size of a control before it actually renders?

In general, you should be able to get the correct size from ArrangeOverride This doesn't include things like Margin, but that probably shouldn't be taken into account. You could either use the size passed as a parameter as your "render" size or use the return value of the base. ArrangeOverride call.

In general, you should be able to get the correct size from ArrangeOverride. This doesn't include things like Margin, but that probably shouldn't be taken into account. You could either use the size passed as a parameter as your "render" size or use the return value of the base.

ArrangeOverride call. EDIT: The OnRender method is called from the Arrange method, after OnArrangeOverride is ultimately called. The OnRenderSizeChanged on the other hand is called from UpdateLayout, which is effectively dispatched to be executed all at once for a given section of the visual tree.

This is why the OnRenderSizeChanged is called after the OnRender. The documentation may refer to the "rendering" as in actually rendered to the screen, not when OnRender is called. WPF can cache the rendering instructions for a given element and execute them when needed.So the fact that OnRender is called before OnRenderSizeChanged, doesn't mean it's actual rendering instructions are committed to the screen at that time.

You can modify your OnRenderSizeChanged to force OnRender to be called again using: protected override void OnRenderSizeChanged(System.Windows. SizeChangedInfo sizeInfo) { Console. WriteLine("OnRenderSizeChanged Entered"); base.

OnRenderSizeChanged(sizeInfo); this. InvalidateVisual(); Console. WriteLine("OnRenderSizeChanged Exited"); } You may also want to skip your OnRender code if RenderSize is "0,0".

Yeah... that's what I had just edited at the bottom of my description above as what we're currently doing as a 'work-around', but that still doesn't explain the OnRenderSizeChanged override not working as the documentation says. Also, the only thing I think that doesn't take into consideration is Margin since that's outside of what gets rendered anyway. Do you know of any other things that aren't taken into consideration?

– MarqueIV Apr 13 at 16:48 @MarquelV - Updated my answer based on your comments. – CodeNaked Apr 13 at 17:03 Looks like just sticking with the ArrangeOverride is what I need to do. You got the answer!

:) – MarqueIV Apr 13 at 17:09.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions