locked
Cannot do cropping on Canvas after dynamically add/remove canvas Eventhandler

    Question

  • I have this canvas inside a ScrollViewer

    original canvas:

    <ScrollViewer Margin="120,20,0,0" x:Name="canvasScr" Grid.Row="0" Grid.RowSpan="4" Grid.Column="0" Grid.ColumnSpan="2" Width="1000" Height="700" >

    VerticalAlignment="Top" HorizontalAlignment="Left" ZoomMode="Enabled" HorizontalScrollMode="Enabled" VerticalScrollMode="Enabled"  MinZoomFactor="1">

     <Canvas  x:Name="canvas" Margin="130,20,321,0" PointerPressed="StartMarking" PointerReleased="StopMarking" PointerMoved="UpdateMarking" Width="700" Height="525"/>

     <Border Width="0" Height="0" x:Name="marking" BorderThickness="2" BorderBrush="Red"/>

    </ScrollViewer>


    1) on Load Page event: remove the events of the canvas : PointerPress, PointerReleased, PointerMoved

    2)  add a button to add the eventhandler and disable the Scrollviewer

     private void btnStopScroll_Click(object sender, RoutedEventArgs e)
            {
                canvasScr.ZoomMode = ZoomMode.Disabled;

               canvas.PointerPressed += StartMarking;
               canvas.PointerReleased += StopMarking;
               canvas.PointerMoved += UpdateMarking;
            }

    Problem: Can not do cropping after adding back the event handlers and disable the scrollViewer

    am I doing right in (1) and (2) ?

    Thanks



    • Edited by FireDance Thursday, November 06, 2014 9:07 AM
    Thursday, November 06, 2014 9:01 AM

Answers

  • What do you mean by cannot do cropping, I set breakpoints at the StopMarking method, I can receive the start position and end position even I disable the ZoomMode of the ScrollViewer.

    However if you disable the scrollviewer control, the mouse event and gesture will not get into the canvas, therefore these two method will not be fired.

            PointerPoint start, end;
            private void StopMarking(object sender, PointerRoutedEventArgs e)
            {
                end = e.GetCurrentPoint(canvas);
                //throw new NotImplementedException();
            }
            private void StartMarking(object sender, PointerRoutedEventArgs e)
            {
                start = e.GetCurrentPoint(canvas);
                //throw new NotImplementedException();
            }

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, November 07, 2014 3:19 AM
    Moderator