Margin showing line numbers.
Inheritance: ICSharpCode.AvalonEdit.Editing.AbstractMargin, IWeakEventListener
Ejemplo n.º 1
0
		// using a method to ensure the local variables can be garbage collected after the method returns
		WeakReference DocumentDoesNotHoldReferenceToLineMargin_CreateMargin(TextDocument textDocument)
		{
			TextView textView = new TextView() {
				Document = textDocument
			};
			LineNumberMargin margin = new LineNumberMargin() {
				TextView = textView
			};
			return new WeakReference(textView);
		}
Ejemplo n.º 2
0
 static void OnShowLineNumbersChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     TextEditor editor = (TextEditor)d;
     var leftMargins = editor.TextArea.LeftMargins;
     if ((bool)e.NewValue) {
         LineNumberMargin lineNumbers = new LineNumberMargin();
         Line line = (Line)DottedLineMargin.Create();
         leftMargins.Insert(0, lineNumbers);
         leftMargins.Insert(1, line);
         var lineNumbersForeground = new Binding("LineNumbersForeground") { Source = editor };
         line.SetBinding(Line.StrokeProperty, lineNumbersForeground);
         lineNumbers.SetBinding(Control.ForegroundProperty, lineNumbersForeground);
     } else {
         for (int i = 0; i < leftMargins.Count; i++) {
             if (leftMargins[i] is LineNumberMargin) {
                 leftMargins.RemoveAt(i);
                 if (i < leftMargins.Count && DottedLineMargin.IsDottedLineMargin(leftMargins[i])) {
                     leftMargins.RemoveAt(i);
                 }
                 break;
             }
         }
     }
 }
Ejemplo n.º 3
0
 // using a method to ensure the local variables can be garbage collected after the method returns
 void DocumentDoesNotHoldReferenceToLineMargin_CreateMargin(TextDocument textDocument, Action finalizeAction)
 {
     TextView textView = new TextViewWithGCCallback(finalizeAction) {
         Document = textDocument
     };
     LineNumberMargin margin = new LineNumberMargin() {
         TextView = textView
     };
 }