// -------------------------------------------------------------------- // 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); var dpi = VisualTreeHelper.GetDpi(this); lineNumbersCanvas.Width = GetFormattedTextWidth(string.Format("{0:0000}", totalLineCount), dpi) + 5; scrollViewer.ScrollChanged += OnScrollChanged; InvalidateBlocks(0); InvalidateVisual(); }; SizeChanged += (s, e) => { if (e.HeightChanged == false) { return; } var dpi = VisualTreeHelper.GetDpi(this); UpdateBlocks(dpi); InvalidateVisual(); }; TextChanged += (s, e) => { totalLineCount = TextUtilities.GetLineCount(Text); InvalidateBlocks(e.Changes.First().Offset); 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) => { totalLineCount = TextUtilities.GetLineCount(Text); InvalidateBlocks(e.Changes.First().Offset); InvalidateVisual(); }; }