AvalonStudio.TextEditor.TextEditor.OnTemplateApplied C# (CSharp) Method

OnTemplateApplied() protected method

protected OnTemplateApplied ( TemplateAppliedEventArgs e ) : void
e TemplateAppliedEventArgs
return void
        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);
                        }
                    };
                }
            }));
        }