This might be a design problem on my part but I'm experiencing what I'm calling race conditions when setting the size of a Canvas (let's call it Canvas A) which is a child of a ScrollViewer. I'm using the size of Canvas A to set the visibility of the scrollbars in the ScrollViewer. However, I also use the visibility of the scrollbars to adjust the size of the Canvas. Wait... let me explain!
(Skip the explanation by scrolling down to the bolded question below).
First, the Canvas I'm talking about has a child that's another Canvas (call it Canvas B). And when Canvas B is larger than Canvas A, I set the size of Canvas A to the size of Canvas B. When Canvas B is smaller than Canvas A, then I set it to the size of the ScrollViewer ViewPorts. Then I want the ScrollViewer to update so that I can set the visibility of the vertical/horizontal scrollbars.
However, when I update the ScrollViewer (using the UpdateLayout method), and when one or both of the scrollbars becomes visibile or collapsed (when they weren't before), then I have to modify the size of Canvas A.
So then I call UpdateLayout() again.
I consider this a race condition because Canvas A's size depends on the ScrollViewer's scrollbar visibility which depend on Canvas A's size, etc.
In my code, I call the code that sets Canvas A's size twice. And I call the code that calls UpdateLayout twice. This happens each time a user of my custom control performs a certain action (not to be too cryptic but I can't discuss the details).
=====> So here's my question (finally!)... I would like to change some properties of the ScrollViewer (or maybe a child element contained within) and see how it would affect the ScrollViewer's layout. Do I actually have to call UpdateLayout to see the changes each time or can I do this programmatically?