2
votes

I have a custom class that extends the in built WPF Canvas called VisualCanvas and it's the main content area for the application grpahics. I have another custom class extending Canvas called SharedTransformCanvas and it will be used for adornments on top of the main content. The SharedTransformCanvas does not have a background colour set so mouse event etc are generally handled by the VisualCanvas. Both canvases have Transform dependency properties and are bound to a view model exposing another object's transform i.e. the canvases are sharing a transform. Both canvases are within a grid of one row which is within a ScrollViewer.

The user can scroll the mouse wheel in the main canvas in order to zoom. This affects the transform shared between the two as I want the adornments to zoom in the same way as the main content and this generally works i.e. the adornments have a synchronised zoom.

The problem is when the user zooms in then scroll bars should appear and they were not so I overrided MeasureOverride on VisualCanvas in order to take the scale transform into account and report a larger size and make scroll bars appear. This solves the problem of the scrollbars appearing when the user zooms in but at the point the user zooms in enough for the scroll bars to appear the content of top SharedTransformCanvas seems to suddenly ignore the transform and jump back to it's size with no transform applied. I have also tried to override MeasureOverride in SharedTransromCanvas to take into account the transform in the same way and report a bigger size but this does not fix the problem.

If I remove the scroll viewer the synchronised zoom seems to work fine but once you zoom too far you miss some content off the screen and have no way to scroll.

I don't understand how the scroll viewer is interacting with the top canvases perception of it's transformation? Can anyone explain this behaviour?

1

1 Answers

1
votes

I ran across this WPF Scale Transform and ScrollViewer - When Zoomed can't scroll beyond original size which highlighted I should proabably be using Layout Transform. I changed it to use a Layout transform and it works. I still don't get why it suddenly ignores the transormation in my above scenario but this fixes my problem.