问题
We have a Canvas contained in a ScrollViewer. Users can add an unlimited number of UserControls that, to oversimplify, are a RichTextControl surrounded by a number of decorative rectangles.
We have an arranger that positions all the UserControls so none overlap. When the arranger runs, it calculates a new position for each UserControl and sets its X and Y on the Canvas.
Something is causing the ScrollViewer to scroll, however, so that after the arranger runs the user might have a different view of all their items.
I looked for an event to hook to see what could be causing the SV to change, but it didn't look like there is an appropriate one. (ManipulationStarted is only available on WP7.)
Is there a property we can bind to, to try to figure out why the SV's horizontal and vertical offsets are changing?
Thanks for any insights into what might be going on.
UPDATE: I have reproduced this in a simpler project. The mischief occurs when the content of a RichTextBox is changed -- the RTB is brought in to view.
Is there any way to prevent this? Some property on the ScrollViewer, perhaps?
TIA...
UPDATE 2: It appears the RTB SizeChanged event causes the ScrollViewer to bring the RTB into view. While we can add a handler for the SizeChanged event, there is no OnSizeChanged overrideable method.
来源:https://stackoverflow.com/questions/6740136/sl-4-monitor-properties-of-scrollviewer