Pregunta

I have added a margin (For adding breakpoints) to the left side of my TextEditor in the following manner:

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());
            ...

The margin is added successfully but now I'd like to color the background of the margin. How can I accomplish this?

¿Fue útil?

Solución

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

You would have to override OnRender:

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

Also, you aren't required to derived fromAbstractMargin - you can use any WPF control you want. AbstractMargin just provides the TextView and Document properties and keeps them up to date. If you don't need those or can implement them yourself, you can just use another base class.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top