// --------------------------------------------------------------------
        // Ctor and event handlers
        // --------------------------------------------------------------------
        public SyntaxHighlightBox()
        {
            InitializeComponent();

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

            Loaded += (s, e) => {
                renderCanvas = (DrawingControl)Template.FindName("PART_RenderCanvas", this);
                scrollViewer = (ScrollViewer)Template.FindName("PART_ContentHost", this);

                scrollViewer.ScrollChanged += OnScrollChanged;

                InvalidateBlocks(0);
                InvalidateVisual();
            };

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

            TextChanged += (s, e) => {
                UpdateTotalLineCount();
                InvalidateBlocks(e.Changes.First().Offset);
                InvalidateVisual();
            };
        }
Example #2
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            renderCanvas      = (DrawingControl)Template.FindName("PART_RenderCanvas", this);
            lineNumbersCanvas = (DrawingControl)Template.FindName("PART_LineNumbersCanvas", this);
            scrollViewer      = (ScrollViewer)Template.FindName("PART_ContentHost", this);

            lineNumbersCanvas.Width = GetFormattedTextWidth(string.Format("{0:0000}", totalLineCount)) + 5;

            scrollViewer.ScrollChanged += OnScrollChanged;

            InvalidateBlocks(0);
            InvalidateVisual();
        }
        // --------------------------------------------------------------------
        // Ctor and event handlers
        // --------------------------------------------------------------------

        public SyntaxHighlightBox()
        {
            InitializeComponent();

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

            Loaded += (s, e) =>
            {
                renderCanvas      = (DrawingControl)Template.FindName("PART_RenderCanvas", this);
                lineNumbersCanvas = (DrawingControl)Template.FindName("PART_LineNumbersCanvas", this);
                scrollViewer      = (ScrollViewer)Template.FindName("PART_ContentHost", this);

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

            TextChanged += (s, e) =>
            {
                UpdateTotalLineCount();
                InvalidateBlocks(e.Changes.First().Offset);
                InvalidateVisual();
            };

            PreviewMouseUp += (s, e) =>
            {
                var sen = e.Source;
                //this.CaretIndex
            };
        }
Example #4
0
		// --------------------------------------------------------------------
		// Ctor and event handlers
		// --------------------------------------------------------------------

		public SyntaxHighlightBox() {
			InitializeComponent();

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

			Loaded += (s, e) => {
				renderCanvas = (DrawingControl)Template.FindName("PART_RenderCanvas", this);
				lineNumbersCanvas = (DrawingControl)Template.FindName("PART_LineNumbersCanvas", this);
				scrollViewer = (ScrollViewer)Template.FindName("PART_ContentHost", this);

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

                if (scrollViewer != null)
                {
                    scrollViewer.ScrollChanged += OnScrollChanged;
                }

				InvalidateBlocks(0);
				InvalidateVisual();
			};

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

			TextChanged += (s, e) => {
				UpdateTotalLineCount();
				InvalidateBlocks(e.Changes.First().Offset);
				InvalidateVisual();
			};
		}