Public Partial Class WpfImageViewer_ExternalScrollBars
Inherits System.Windows.Window
#Region "Constructors"
Public Sub New()
InitializeComponent()
' ...
AddHandler imageViewer.ImageLoaded, New System.EventHandler(Of Vintasoft.Imaging.ImageLoadedEventArgs)(AddressOf imageViewer_ImageLoaded)
AddHandler imageViewer.ZoomChanged, New System.EventHandler(Of Vintasoft.Imaging.UI.ZoomChangedEventArgs)(AddressOf imageViewer_ZoomChanged)
AddHandler imageViewer.SizeChanged, New System.Windows.SizeChangedEventHandler(AddressOf imageViewer_SizeChanged)
AddHandler horizontalScrollBar.ValueChanged, New System.Windows.RoutedPropertyChangedEventHandler(Of Double)(AddressOf ScrollBar_ValueChanged)
AddHandler verticalScrollBar.ValueChanged, New System.Windows.RoutedPropertyChangedEventHandler(Of Double)(AddressOf ScrollBar_ValueChanged)
' ...
imageViewer.AutoScroll = False
End Sub
#End Region
#Region "Methods"
''' <summary>
''' Image is loaded in image viewer.
''' </summary>
Private Sub imageViewer_ImageLoaded(sender As Object, e As Vintasoft.Imaging.ImageLoadedEventArgs)
SetScrollBarsParams()
End Sub
''' <summary>
''' Image viewer size is changed.
''' </summary>
Private Sub imageViewer_SizeChanged(sender As Object, e As System.Windows.SizeChangedEventArgs)
SetScrollBarsParams()
End Sub
''' <summary>
''' Image viewer zoom is changed.
''' </summary>
Private Sub imageViewer_ZoomChanged(sender As Object, e As Vintasoft.Imaging.UI.ZoomChangedEventArgs)
SetScrollBarsParams()
End Sub
''' <summary>
''' Sets parameters of scroll bars.
''' </summary>
Private Sub SetScrollBarsParams()
' initialize horizontal scroll bar
horizontalScrollBar.Minimum = 0
horizontalScrollBar.Maximum = imageViewer.ViewerState.AutoScrollSize.Width
horizontalScrollBar.Track.ViewportSize = imageViewer.ActualWidth
' initialize vertical scroll bar
verticalScrollBar.Minimum = 0
verticalScrollBar.Maximum = imageViewer.ViewerState.AutoScrollSize.Height
verticalScrollBar.Track.ViewportSize = imageViewer.ActualHeight
End Sub
''' <summary>
''' Scroolbar is changed.
''' </summary>
Private Sub ScrollBar_ValueChanged(sender As Object, e As System.Windows.RoutedPropertyChangedEventArgs(Of Double))
Dim currentPosition As New System.Windows.Point(horizontalScrollBar.Value, verticalScrollBar.Value)
imageViewer.ViewerState.AutoScrollPosition = currentPosition
End Sub
#End Region
End Class