0

I have a canvas in WPF which contains an image control as seen below

<Canvas x:Name="ImageContainer" 
                            Background="Transparent" 
                                  Height="{Binding ElementName=panel2, Path=ActualHeight}"
                                  Width="{Binding ElementName=panel2, Path=ActualWidth}"
                                >

                                <local:ZoomBorder 
                                          x:Name="pictureBox1Border"
                                      MouseWheel="pictureBox1Border_MouseWheel"
                                      PreviewMouseRightButtonDown="pictureBox1Border_PreviewMouseRightButtonDown"
                                      MouseLeave="pictureBox1Border_MouseLeave"
                                      MouseEnter="pictureBox1Border_MouseEnter"
                            ClipToBounds="True"
                                      >


                                    <Image x:Name="pictureBox1"
                                           HorizontalAlignment="Center"
                                           VerticalAlignment="Center"
                               MouseDown="pictureBox1_MouseDown"
                               MouseMove="pictureBox1_MouseMove"
                                   MouseRightButtonUp="pictureBox1_MouseRightButtonUp"
                                   MouseLeftButtonUp="pictureBox1_MouseLeftButtonUp"
                                      Width="{Binding Path=ActualWidth,ElementName=ImageContainer}"
                                       Height="{Binding Path=ActualHeight,ElementName=ImageContainer}"
                                       Stretch="Uniform"
                              />

                                </local:ZoomBorder>

                        </Canvas>

I implemented this using some of the code from the answer in this answer by Wiesław Šoltés question.

Now I want to add a scrollviewer around the canvas so that when I zoom the image, I can scroll the image around. But it doesn't work. The height and width of the scrollbars remain the same even when I zoom image. Can anyone direct me on how to make scrollviewer work normally?

  • Why do you have the canvas and zoomborder at all rather than just an image in a scrollviewer? – Andy Jan 21 '19 at 15:43
  • The zoomborder implements functionality for panning, and zooming on the image. I included the canvas so that I could draw a rectangle on the image. i.e. selection rectangle. Now when I add scrollbar around canvas, it doesn't work at all when image is zoomed. It seems the size of canvas never changes. And if I add scrollviewer around image, zoomborder functionality won't work. – emile keen Jan 21 '19 at 18:07

0 Answers0