2

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

1 Answer 1

2

You should try to handle RequestBringIntoView event raised when the item receives focus and prevent this event to be bubbled to ScrollViewer. One good place to mark these events as handled is at Canvas level.

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome, this was exactly what I needed +1. Set e.Handled = true in my canvas RequestBringIntoView as suggested and it works perfectly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.