protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
editor = this.Find<TextEditor.TextEditor>("editor");
editor.CaretChangedByPointerClick += Editor_CaretChangedByPointerClick;
editor.EditorScrolled += Editor_EditorScrolled;
editorViewModel = DataContext as EditorViewModel;
if (editorViewModel != null && editor != null)
{
editorViewModel.Model.Editor = editor;
editor.Focus();
}
}