Beispiel #1
0
        protected override void OnApplyTemplate()
        {
            container = this.GetTemplateChild(ContainerName) as Grid;
            textBox = this.GetTemplateChild(TextBoxName) as TextBox;
            inkCanvas = this.GetTemplateChild(InkCanvasName) as InkCanvas;
            inkBorder = this.GetTemplateChild(InkBorderName) as Border;
            inkWindow = this.GetTemplateChild(InkWindowName) as Popup;

            inkRecognizerContainer = new InkRecognizerContainer();
            recognizers = inkRecognizerContainer.GetRecognizers();

            // Set the text services so we can query when language changes
            textServiceManager = CoreTextServicesManager.GetForCurrentView();
            textServiceManager.InputLanguageChanged += TextServiceManager_InputLanguageChanged;

            SetDefaultRecognizerByCurrentInputMethodLanguageTag();

            // Create a timer that expires after 1 second
            recognitionTimer = new DispatcherTimer();
            recognitionTimer.Interval = new TimeSpan(0, 0, 1);
            recognitionTimer.Tick += RecoTimer_Tick;

            pointerTimer = new DispatcherTimer();
            pointerTimer.Interval = new TimeSpan(0, 0, 2);
            pointerTimer.Tick += PointerTimer_Tick;

            textBox.PointerEntered += TextBox_PointerEntered;
            textBox.AddHandler(PointerPressedEvent, new PointerEventHandler(TextBox_PointerPressed), true);
            textBox.SelectionChanged += TextBox_SelectionChanged;

            inkCanvas.PointerEntered += InkCanvas_PointerEntered;
            inkCanvas.InkPresenter.StrokesCollected += InkCanvas_StrokesCollected;
            inkCanvas.InkPresenter.StrokeInput.StrokeStarted += InkCanvas_StrokeStarted;
            inkCanvas.InkPresenter.StrokesErased += InkPresenter_StrokesErased;
            
            // Initialize drawing attributes. These are used in inking mode.
            InkDrawingAttributes drawingAttributes = new InkDrawingAttributes();
            drawingAttributes.Color = InkColor;
            double penSize = PenSize;
            drawingAttributes.Size = new Windows.Foundation.Size(penSize, penSize);
            drawingAttributes.IgnorePressure = false;
            drawingAttributes.FitToCurve = true;

            // Initialize the InkCanvas
            inkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(drawingAttributes);
            inkCanvas.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Pen;

            //InputPane inputPane = InputPane.GetForCurrentView();
            //inputPane.Showing += InputPane_Showing;

            this.SizeChanged += InkTextBox_SizeChanged;

            enableText();
            base.OnApplyTemplate();
        }