Use the Mouse Wheel action methods that are defined by the IScrollInfo interface
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="ScrollViewer_Methods.Window1"
Title="ScrollViewer IScrollInfo Sample"
Loaded="onLoad">
<DockPanel>
<TextBlock DockPanel.Dock="Top" FontSize="20" FontWeight="Bold" Margin="10">IScrollInfo Interface Methods</TextBlock>
<StackPanel DockPanel.Dock="Left" Width="150">
<Button Click="spMouseWheelDown">MouseWheelDown</Button>
<Button Click="spMouseWheelUp">MouseWheelUp</Button>
<Button Click="spMouseWheelLeft">MouseWheelLeft</Button>
<Button Click="spMouseWheelRight">MouseWheelRight</Button>
</StackPanel>
<Border BorderBrush="Black" Background="White" BorderThickness="2" Width="500" Height="500">
<ScrollViewer Name="sv1" CanContentScroll="True" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible">
<StackPanel Name="sp1">
<Button>Button 1</Button>
<Button>Button 5</Button>
<Rectangle Width="700" Height="500" Fill="Green"/>
<TextBlock>Rectangle 3</TextBlock>
</StackPanel>
</ScrollViewer>
</Border>
</DockPanel>
</Window>
//File:Window.xaml.vb
Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Controls.Primitives
Imports System.Windows.Documents
Imports System.Windows.Navigation
Imports System.Text
Namespace ScrollViewer_Methods
Public Partial Class Window1
Inherits Window
Private Sub onLoad(sender As Object, e As System.EventArgs)
DirectCast(sp1, IScrollInfo).CanVerticallyScroll = True
DirectCast(sp1, IScrollInfo).CanHorizontallyScroll = True
DirectCast(sp1, IScrollInfo).ScrollOwner = sv1
End Sub
Private Sub spMouseWheelDown(sender As Object, e As RoutedEventArgs)
DirectCast(sp1, IScrollInfo).MouseWheelDown()
End Sub
Private Sub spMouseWheelUp(sender As Object, e As RoutedEventArgs)
DirectCast(sp1, IScrollInfo).MouseWheelUp()
End Sub
Private Sub spMouseWheelLeft(sender As Object, e As RoutedEventArgs)
DirectCast(sp1, IScrollInfo).MouseWheelLeft()
End Sub
Private Sub spMouseWheelRight(sender As Object, e As RoutedEventArgs)
DirectCast(sp1, IScrollInfo).MouseWheelRight()
End Sub
End Class
End Namespace
Related examples in the same category