I have a Canvas with a containing a label. I want to move the label around the Canvas. Also the Canvas has a ScrollViewer.
The Canvas is greater then the form. If the label is at a certain position then the ScrollViewer must scroll to the left.
XAML:
<Window>
Title="MainWindow" Height="600"  MinWidth="700">         
<Grid Margin="10">
    <Grid.RowDefinitions>
        <RowDefinition x:Name="g001"  Height ="10" />
        <RowDefinition x:Name="g002"  Height ="50" />
        <RowDefinition x:Name="g003"  Height ="200*" />
    </Grid.RowDefinitions>
    <DockPanel Grid.Row="1">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition x:Name="g010"  Width ="180" />
                <ColumnDefinition x:Name="g011" Width ="100*" />
            </Grid.ColumnDefinitions>
            <DockPanel Grid.Column="1">
                <ScrollViewer x:Name="SCxx" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden">
                    <Canvas x:Name="CanTest" Background="CadetBlue" Width="500" HorizontalAlignment="Left" ClipToBounds="True">
                        <StackPanel x:Name="spDes01" Orientation="Horizontal"/>
                    </Canvas>
                </ScrollViewer>
            </DockPanel>
        </Grid>
    </DockPanel>
    <DockPanel Grid.Row="2">
        <Grid>
            <DockPanel Grid.Row="2" Grid.Column="1">
                <ScrollViewer ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition x:Name="g020"  Width ="180" />
                            <ColumnDefinition x:Name="g021" Width ="180*" />
                            <ColumnDefinition Width="411*"/>
                        </Grid.ColumnDefinitions>
                        <DockPanel Grid.Column="1" Grid.ColumnSpan="2" HorizontalAlignment="Left">
                            <local:UcTest x:Name="uc_screen" />
                        </DockPanel>
                        <DockPanel Grid.Column="0" >
                            <Canvas Height="300" VerticalAlignment="Top">
                                <Canvas.Background>
                                    <LinearGradientBrush StartPoint="0,1" EndPoint="1.2,0">
                                        <GradientStop Color="White" Offset="1"/>
                                        <GradientStop Color="LightBlue" Offset="0"/>
                                    </LinearGradientBrush>
                                </Canvas.Background>
                                <Button x:Name="BtnClick001"  Content=" 20"  Height="22"  Width="81" Canvas.Left="47" Canvas.Top="40"  />
                                <Button x:Name="BtnClick002"  Content=" 40"  Height="22"  Width="81" Canvas.Left="47" Canvas.Top="67"  />
                                <Button x:Name="BtnClick003"  Content=" 60"  Height="22"  Width="81" Canvas.Left="47" Canvas.Top="94"  />
                                <Button x:Name="BtnClick004"  Content=" 80"  Height="22"  Width="81" Canvas.Left="47" Canvas.Top="121" />
                                <Button x:Name="BtnClick005"  Content="100"  Height="22"  Width="81" Canvas.Left="47" Canvas.Top="148" />
                                <Button x:Name="BtnClick006"  Content="120"  Height="22"  Width="81" Canvas.Left="47" Canvas.Top="175" />
                            </Canvas>
                        </DockPanel>
                    </Grid>
                </ScrollViewer>
            </DockPanel>
        </Grid>
    </DockPanel>
</Grid>
MainWindow :
Class MainWindow
Public Sub New()
    InitializeComponent()
End Sub
Private Sub uc_screen_DoWat(pp As Double) Handles uc_screen.DoWat
    SCxx.ScrollToHorizontalOffset(pp)
End Sub
Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
    makebuttons(100)
End Sub
Public Sub makebuttons(_Width As Integer)
    Dim stLeftpos As Double
    Dim jjWidth As Double
    Dim posX As Double = 0
    Dim tMoveme As New Thickness
    stLeftpos = 0
    jjWidth = _Width
    For jj = 0 To 1825
        Dim btn As New Button
        'Margin = left,top,right,bottom
        tMoveme.Left = 0 'stLeftpos
        tMoveme.Top = 0
        tMoveme.Right = 0
        tMoveme.Bottom = 0
        With btn
            .Margin = tMoveme
            .Width = jjWidth
            .Height = 20
            .Content = jj
        End With
        stLeftpos = stLeftpos + jjWidth
        spDes01.Children.Add(btn)
    Next
    CanTest.Width = stLeftpos
    uc_screen.SetWidth(stLeftpos)
End Sub
End Class
And The Usercontrol:
Public Class UcTest
Public Event DoWat(pp As Double)
Dim FirstXPos, FirstYPos As Double
Dim bMouseDown As Boolean = False
Private Sub SC_User_x(sender As Object, e As ScrollChangedEventArgs) Handles SC_User.ScrollChanged
    Dim item As Canvas = DirectCast(CanUser, Canvas)
    Dim CtrPoint As New Point()
    CtrPoint = item.PointToScreen(New Point(0, 0))
    Dim pp As Double = e.HorizontalOffset
    RaiseEvent DoWat(pp)
End Sub
Public Function GetWidth()
    GetWidth = CanUser.Width
End Function
Public Sub SetWidth(setdd As Double)
    CanUser.Width = setdd
End Sub
Private Sub UcTest_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
    Dim DL As New Label
    Dim dGetal As Double
    Dim tMoveme As New Thickness
    For i = 1 To 5
        DL = New Label
        dGetal = 100
        DL.SetValue(Canvas.LeftProperty, dGetal)
        DL.Name = "aaa"
        DL.Height = 30
        DL.Foreground = New SolidColorBrush(Colors.White)
        Select Case i
            Case 1
                DL.Width = 800
                dGetal = 100
                DL.SetValue(Canvas.TopProperty, dGetal)
                DL.Background = New SolidColorBrush(Colors.Red)
            Case 2
                DL.Width = 400
                dGetal = 120
                DL.SetValue(Canvas.TopProperty, dGetal)
                DL.Background = New SolidColorBrush(Colors.Blue)
            Case 3
                DL.Width = 200
                dGetal = 140
                DL.SetValue(Canvas.TopProperty, dGetal)
                DL.Background = New SolidColorBrush(Colors.Yellow)
            Case 4
                DL.Width = 190
                dGetal = 150
                DL.SetValue(Canvas.TopProperty, dGetal)
                DL.Background = New SolidColorBrush(Colors.Green)
            Case 5
                DL.Width = 20
                dGetal = 160
                DL.SetValue(Canvas.TopProperty, dGetal)
                DL.Background = New SolidColorBrush(Colors.DarkGray)
                dGetal = 300
                DL.SetValue(Canvas.LeftProperty, dGetal)
        End Select
        DL.Content = "Jaja"
        DL.Opacity = 0.5
        AddHandler DL.MouseMove, AddressOf BtnMouseMove
        AddHandler DL.MouseDown, AddressOf BtnMouseDown
        AddHandler DL.MouseUp, AddressOf BtnMouseUp
        AddHandler DL.MouseLeave, AddressOf BtnMouseLeave
        CanUser.Children.Add(DL)
    Next
End Sub
Private Sub BtnMouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
    Dim tMoveme As New Thickness
    Dim ikeuze As Integer
    Dim vBlok As Double
    Dim wnd As Window = Window.GetWindow(Me)
    Dim position As Point = e.MouseDevice.GetPosition(wnd)
    If bMouseDown = False Then Exit Sub
    sender.content = bMouseDown
    ikeuze = 2 ' Verschillende manieren
    Select Case ikeuze
        Case 1
            sender.SetValue(Canvas.LeftProperty, e.GetPosition((sender).Parent).X - FirstXPos)
            SC_User.ScrollToHorizontalOffset(sender.getValue(Canvas.LeftProperty) - (e.GetPosition((sender).Parent).X - FirstXPos) / 20)
        Case 2
            If (position.X / (Me.ActualWidth / 100)) > 95 Then
                vBlok = (Me.ActualWidth * 100) / sender.width
                SC_User.ScrollToHorizontalOffset(sender.getValue(Canvas.LeftProperty) - (vBlok))
                sender.SetValue(Canvas.LeftProperty, e.GetPosition((sender).Parent).X - (e.GetPosition((sender).Parent).Y - FirstYPos) + (vBlok))
            Else
                sender.SetValue(Canvas.LeftProperty, e.GetPosition((sender).Parent).X - FirstXPos)
                sender.SetValue(Canvas.TopProperty, e.GetPosition((sender).Parent).Y - FirstYPos)
            End If
    End Select
End Sub
Private Sub BtnMouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
    Dim dGetal As Double = 0
    bMouseDown = True
    FirstXPos = e.GetPosition(sender).X
    FirstYPos = e.GetPosition(sender).Y
End Sub
Private Sub BtnMouseUp(ByVal sender As Object, ByVal e As MouseEventArgs)
    bMouseDown = False
    sender.content = bMouseDown
End Sub
Private Sub BtnMouseLeave(ByVal sender As Object, ByVal e As MouseEventArgs)
    bMouseDown = False
    sender.content = bMouseDown
End Sub
Private Sub SC_User_ScrollChanged(sender As Object, e As ScrollChangedEventArgs) Handles SC_User.ScrollChanged
    Dim item As Canvas = DirectCast(CanUser, Canvas)
    Dim CtrPoint As New Point()
    CtrPoint = item.PointToScreen(New Point(0, 0))
    Dim pp As Double = e.HorizontalOffset
End Sub
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
    SC_User.ScrollToHome()
End Sub
End Class