WPF Image Zooming

后端 未结 4 720
独厮守ぢ
独厮守ぢ 2021-02-09 14:33

I have a Viewbox with an Image inside of it. This is great since the Viewbox will scale the Image to fit the window. However, I need to be able to zoom the image to its full siz

4条回答
  •  有刺的猬
    2021-02-09 15:30

    Based on your edit that you need to toggle the two approaches, I would do this in one of two ways.

    1. Have two elements with the image. The Image element inside a ScrollViewer without the Viewbox will give you the full size image, and the Viewbox version will scale it. Then you can toggle the two depending on what you want to show.

    2. Use a binding expression on the Height and Width properties of the Image and enclose it inside the scrollviewer. When you want to scale it (in some sort of trigger), set the Height to a binding expression that accesses the ActualHeight property of the ScrollViewer or whatever container is just above that (using RelativeSource to access the nearest ancestor something like the following):

      {Binding Path=ActualHeight, 
               RelativeSource={RelativeSource AncestorType={x:Type ScrollViewer}}}
      

提交回复
热议问题