2012-07-19 84 views
1

保证金我加了保证金(用于添加断点)到我的文本编辑左侧以下方式:着色上Avalonedit

public partial class LogicSimViewCodeWPFCtrl : UserControl 
    { 

private class BreakPointMargin : AbstractMargin 
    { 
     private const int margin = 20; 
     protected override HitTestResult HitTestCore(PointHitTestParameters hitTestParameters) 
     { 
      return new PointHitTestResult(this, hitTestParameters.HitPoint); 
     } 

     protected override Size MeasureOverride(Size availableSize) 
     { 
      return new Size(margin, 0); 
     } 
    } 
} 

    private void LogicCodeInit() 
    { 
     try 
     { 
      TxtEditCodeViewer.TextArea.LeftMargins.Insert(0, new BreakPointMargin()); 
      ... 

保证金增加成功,但现在我想以色边距的背景。我怎样才能做到这一点?

回答

3

http://community.sharpdevelop.net/forums/t/16047.aspx

你将不得不重写OnRender

protected override void OnRender(DrawingContext drawingContext) 
    { 
     Size renderSize = this.RenderSize; 
     drawingContext.DrawRectangle(SystemColors.ControlBrush, null, 
            new Rect(0, 0, renderSize.Width, renderSize.Height)); 

而且,你是不是需要从AbstractMargin衍生的 - 你可以使用任何你想要的WPF控件。 AbstractMargin只是提供了TextViewDocument属性并使它们保持最新状态。如果你不需要这些或者可以自己实现它们,你可以使用另一个基类。