/// <summary> /// Hock event handlers and restore editor states (if any) or defaults /// when the control is fully loaded. /// </summary> /// <param name="obj"></param> /// <param name="args"></param> private void OnLoaded(object obj, RoutedEventArgs args) { try { // This adds a search panel into the edit // It is available via Ctrl-F SearchPanel.Install(this); // Remove rounded corners from text selection this.TextArea.SelectionCornerRadius = 0; this.TextArea.SelectionBorder = null; // Initialize Diff line background color rendering _DiffBackgroundRenderer = new DiffLineBackgroundRenderer(this); this.TextArea.TextView.BackgroundRenderers.Add(_DiffBackgroundRenderer); // Customize display of line numbers using real lines (shown with a number) // and imaginary lines (shown without a number) // Switch off default line handler in AvalonEdit ShowLineNumbers = false; this.TextArea.LeftMargins.Clear(); var leftMargins = this.TextArea.LeftMargins; // Configure and insert custom line number margin indicator LineNumberMargin lineNumbers = new CustomLineNumberMargin(this); Line line = (Line)DottedLineMargin.Create(); leftMargins.Insert(0, lineNumbers); leftMargins.Insert(1, line); var lineNumbersForeground = new Binding("LineNumbersForeground") { Source = this }; line.SetBinding(Shape.StrokeProperty, lineNumbersForeground); lineNumbers.SetBinding(Control.ForegroundProperty, lineNumbersForeground); // Attach more event handlers this.GotFocus += DiffView_GotFocus; ////this.Focus(); ////this.ForceCursor = true; // Restore cursor position for CTRL-TAB Support http://avalondock.codeplex.com/workitem/15079 this.ScrollToHorizontalOffset(this.EditorScrollOffsetX); this.ScrollToVerticalOffset(this.EditorScrollOffsetY); // Highlight current line in editor (even if editor is not focused) via themable dp-property this.AdjustCurrentLineBackground(); this.TextArea.Caret.PositionChanged += Caret_PositionChanged; } catch { // catch this to make sure initialization can continue... } }
/// <summary> /// Hock event handlers and restore editor states (if any) or defaults /// when the control is fully loaded. /// </summary> /// <param name="obj"></param> /// <param name="args"></param> private void OnLoaded(object obj, RoutedEventArgs args) { try { // This adds a search panel into the edit // It is available via Ctrl-F SearchPanel.Install(this); // Remove rounded corners from text selection this.TextArea.SelectionCornerRadius = 0; this.TextArea.SelectionBorder = null; // Initialize Diff line background color rendering _DiffBackgroundRenderer = new DiffLineBackgroundRenderer(this); this.TextArea.TextView.BackgroundRenderers.Add(_DiffBackgroundRenderer); DisplayCustomLineNumbers(ShowCustomLineNumbers); // Attach more event handlers this.GotFocus += DiffView_GotFocus; ////this.Focus(); ////this.ForceCursor = true; // Restore cursor position for CTRL-TAB Support http://avalondock.codeplex.com/workitem/15079 this.ScrollToHorizontalOffset(this.EditorScrollOffsetX); this.ScrollToVerticalOffset(this.EditorScrollOffsetY); // Highlight current line in editor (even if editor is not focused) via themable dp-property this.AdjustCurrentLineBackground(); this.TextArea.Caret.PositionChanged += Caret_PositionChanged; } catch { // catch this to make sure initialization can continue... } }