public SyntaxHighlightTextBox()
        {
            InitializeComponent();

            MaxLineCountInBlock = 100;
            LineHeight          = FontSize * 1.3;
            _totalLineCount     = 1;
            _blocks             = new List <InnerTextBlock>();

            this.TextBox1.Loaded += (s, e) =>
            {
                _renderCanvas      = (DrawingControl)TextBox1.Template.FindName("PART_RenderCanvas", this.TextBox1);
                _lineNumbersCanvas = (DrawingControl)TextBox1.Template.FindName("PART_LineNumbersCanvas", this.TextBox1);
                var scrollViewer = (ScrollViewer)TextBox1.Template.FindName("PART_ContentHost", this.TextBox1);
                _lineNumbersSeparator = (Line)TextBox1.Template.FindName("lineNumbersSeparator", this.TextBox1);

                if (_lineNumbersCanvas != null)
                {
                    _lineNumbersCanvas.Width = GetFormattedTextWidth(string.Format("{0:0000}", _totalLineCount)) + 5;
                }

                scrollViewer.ScrollChanged += onScrollChanged;

                invalidateBlocks(0);
                InvalidateVisual();
            };

            SizeChanged += (s, e) =>
            {
                if (e.HeightChanged == false)
                {
                    return;
                }
                updateBlocks();
                InvalidateVisual();
            };

            this.TextBox1.TextChanged += (s, e) =>
            {
                updateTotalLineCount();
                invalidateBlocks(e.Changes.First().Offset);
                InvalidateVisual();
            };
        }
        public SyntaxHighlightTextBox()
        {
            InitializeComponent();

            MaxLineCountInBlock = 100;
            LineHeight = FontSize * 1.3;
            _totalLineCount = 1;
            _blocks = new List<InnerTextBlock>();

            this.TextBox1.Loaded += (s, e) =>
             {
                 _renderCanvas = (DrawingControl)TextBox1.Template.FindName("PART_RenderCanvas", this.TextBox1);
                 _lineNumbersCanvas = (DrawingControl)TextBox1.Template.FindName("PART_LineNumbersCanvas", this.TextBox1);
                 var scrollViewer = (ScrollViewer)TextBox1.Template.FindName("PART_ContentHost", this.TextBox1);
                 _lineNumbersSeparator = (Line)TextBox1.Template.FindName("lineNumbersSeparator", this.TextBox1);

                 if (_lineNumbersCanvas != null)
                     _lineNumbersCanvas.Width = GetFormattedTextWidth(string.Format("{0:0000}", _totalLineCount)) + 5;

                 scrollViewer.ScrollChanged += onScrollChanged;

                 invalidateBlocks(0);
                 InvalidateVisual();
             };

            SizeChanged += (s, e) =>
            {
                if (e.HeightChanged == false)
                    return;
                updateBlocks();
                InvalidateVisual();
            };

            this.TextBox1.TextChanged += (s, e) =>
            {
                updateTotalLineCount();
                invalidateBlocks(e.Changes.First().Offset);
                InvalidateVisual();
            };
        }