I was reading about this UpdateLayout() method in MSDN.
It says:
Ensures that all visual child elements of this element are properly updated for layout.
But I don't understand what is meant by layout not updated properly.
I have been working with Silverlight/WPF for over a year, but I still haven't used this method once.
So can someone give me an example that will require use of this method? So I can really understand what it does and when I should use it?
You might want to call this if you need a control to immediately complete its layout so that you can do something based on that. For example, you might call UpdateLayout
on a child control so that it gets an ActualHeight
and ActualWidth
, if you want do do something else based on that (eg position it, or draw something with a corresponding size).
From my research, UpdateLayout
seems to be a very forceful way to get all controls on the layout to update. However, in most cases, the layout system is smart enough and quick enough to update appropriately on its own. Everything that I have read leads me to believe that this call is only needed if you are doing a lot of layout modification (adding controls and moving them around) and you need one particular layout scenario to be displayed while the rest of the update stack is completed (however I still have yet to see a good example to display this...the normal layout algorithm seems to be just that good). This MSDN article on layout should help clarify things.
However, from the above:
The UpdateLayout method forces a recursive layout update, and is frequently not necessary
and this documentation
Frequent calls to InvalidateArrange, or in particular to UpdateLayout, have significant performance consequences if large numbers of elements exist in the UI. Avoid calling this method unless you absolutely require precise layout state for subsequent calls to other APIs in your code.
In conclusion to directly answer your question. This is mostly done on its own with internal UI layout logic, and you will most likely never need to use it. By the above, it seems to me that it would be pretty obvious when you do need to use it (and it is not for threading as many, including myself had thought)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With