我想在包含图像控件(WPF / C#)的画布周围添加一个scrollviewer

时间:2019-01-21 15:30:25

标签: c# wpf canvas scrollviewer

我在WPF中有一个画布,其中包含一个如下所示的图像控件

<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>

我使用这个answer by Wiesław Šoltés问题中答案的一些代码来实现这一点。

现在,我想在画布周围添加一个滚动查看器,以便在缩放图像时可以在图像周围滚动。但这是行不通的。即使我缩放图像,滚动条的高度和宽度也保持不变。谁能指导我如何使scrollviewer正常工作?

0 个答案:

没有答案