I've the following problem: when an item in the canvas is selected (to be erased), the scrollviewer is always reset to 0: this is due to the focus in the example code. If the focus() is removed, the scrollviewer is Ok, but the selected item now can't be erased!>
Mainwindow.Xaml code:
<Border Grid.Row="1" BorderThickness="1" BorderBrush="Navy" Margin="2" Padding="2" >
<ScrollViewer Name="Posizione_scrollbar" HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto">
Protected Overrides Sub OnPreviewMouseDown(ByVal e As System.Windows.Input.MouseButtonEventArgs)
MyBase.OnPreviewMouseDown(e)
' usual selection business
Dim designer As DesignerCanvas = TryCast(VisualTreeHelper.GetParent(Me), DesignerCanvas)
If designer IsNot Nothing Then
If (Keyboard.Modifiers And (ModifierKeys.Shift Or ModifierKeys.Control)) <> ModifierKeys.None Then
If Me.IsSelected Then
designer.SelectionService.RemoveFromSelection(Me)
Else
designer.SelectionService.AddToSelection(Me)
End If
ElseIf Not Me.IsSelected Then
If MainViewModel.Instance.ActiveDiagram.STMonitor = False Then
designer.SelectionService.SelectItem(Me)
End If
End If
'Here is the problem: the canvas scrollbar is resetted to 0!
Me.Focus()
End If
'True per avere la gestione col tasto sinistro del mouse
e.Handled = True
End Sub