protected override void OnTemplateApplied(TemplateAppliedEventArgs e)
        {
            TextView = e.NameScope.Find <TextView>("textView");

            LogicalChildren.Add(TextView);

            disposables.Add(TextDocumentProperty.Changed.Subscribe(args =>
            {
                if (args.NewValue != null)
                {
                    // Todo unsubscribe these events.
                    TextDocument.Changing += (sender, ee) =>
                    {
                        TextDocument?.UndoStack.PushOptional(new RestoreCaretAndSelectionUndoAction(this));

                        if (BeforeTextChangedCommand != null)
                        {
                            BeforeTextChangedCommand.Execute(null);
                        }
                    };

                    TextDocument.Changed += (sender, ee) =>
                    {
                        InvalidateVisual();

                        LineHeight = TextView.CharSize.Height;

                        if (TextChangedCommand != null && TextChangedCommand.CanExecute(null))
                        {
                            TextChangedCommand.Execute(null);
                        }
                    };
                }
            }));
        }
Exemple #2
0
        protected override void OnTemplateApplied(TemplateAppliedEventArgs e)
        {
            TextView        = e.NameScope.Find <TextView>("textView");
            TextView.Cursor = new Cursor(StandardCursorType.Ibeam);

            //textView.BackgroundRenderers.Clear();
            //textView.DocumentLineTransformers.Clear();

            //textView.BackgroundRenderers.Add(new SelectedLineBackgroundRenderer());
            //textView.BackgroundRenderers.Add(new ColumnLimitBackgroundRenderer());
            //textView.BackgroundRenderers.Add(new SelectionBackgroundRenderer());
            //textView.DocumentLineTransformers.Add(new SelectedWordTextLineTransformer(this));

            disposables.Add(TextDocumentProperty.Changed.Subscribe(args =>
            {
                if (args.NewValue != null)
                {
                    // Todo unsubscribe these events.
                    TextDocument.Changing += (sender, ee) =>
                    {
                        TextDocument?.UndoStack.StartUndoGroup();
                        TextDocument?.UndoStack.PushOptional(new RestoreCaretAndSelectionUndoAction(this));

                        if (BeforeTextChangedCommand != null)
                        {
                            BeforeTextChangedCommand.Execute(null);
                        }
                    };

                    TextDocument.Changed += (sender, ee) =>
                    {
                        TextDocument?.UndoStack.EndUndoGroup();

                        InvalidateVisual();

                        LineHeight = TextView.CharSize.Height;

                        textChangedDelayTimer.Stop();
                        textChangedDelayTimer.Start();
                    };
                }
            }));
        }