Esempio n. 1
0
        //For controlling the InkCanvas
        private void raiseInkCanvasMouseEvent(string eventName)
        {
            switch (eventName)
            {
            case "MouseUpEvent":
                //Raise the InkCanvas mouse up event
                //if (hoveredInkCanvas != null)
                if (hoveredInkCanvas != null && inkCanvasMouseDown == true)
                {
                    //======Start of method 1========
                    hoveredInkCanvas.RaiseEvent(new MouseButtonEventArgs(Mouse.PrimaryDevice, Environment.TickCount, MouseButton.Left)
                    {
                        RoutedEvent = InkCanvas.PreviewMouseUpEvent
                    });
                    inkCanvasMouseDown = false;
                    hoveredInkCanvas.ReleaseMouseCapture();
                    //=======End of method 1=========
                }
                break;

            case "MouseDownEvent":
                //======Start of method 1========(to be used with Raising InkcCanvas mouse down event)
                // Problem: can not correct show the drawn immediately, of shown after finishing one stroke
                // Findings: 1. this method is done by simulating mouse down event
                //           2. may be missing the event for adding stroke to stroke property of InkCanvas

                inkCanvasMouseDown = true;
                hoveredInkCanvas.RaiseEvent(new MouseButtonEventArgs(Mouse.PrimaryDevice, Environment.TickCount, MouseButton.Left)
                {
                    RoutedEvent = InkCanvas.PreviewMouseLeftButtonDownEvent
                });
                hoveredInkCanvas.RaiseEvent(new MouseButtonEventArgs(Mouse.PrimaryDevice, Environment.TickCount, MouseButton.Left)
                {
                    RoutedEvent = InkCanvas.PreviewMouseDownEvent
                });
                hoveredInkCanvas.Focus();
                hoveredInkCanvas.CaptureMouse();
                hoveredInkCanvas.RaiseEvent(new MouseButtonEventArgs(Mouse.PrimaryDevice, Environment.TickCount, MouseButton.Left)
                {
                    RoutedEvent = InkCanvas.MouseDownEvent
                });
                //hoveredInkCanvas.RaiseEvent(new InkCanvasStrokeCollectedEventArgs(new Stroke(new StylusPointCollection(new StylusPointDescription()))));
                //=======End of method 1=========
                break;
            }
        }