From 9b6064e87eb04517ca0da2496048a254869b360b Mon Sep 17 00:00:00 2001 From: John Colvin Date: Thu, 2 May 2019 18:28:02 -0500 Subject: [PATCH] SPARK-2377 OB Last Message column displays strange alignment when resizing and/or scrolling --- .../Controls/DIYGrid/CellRender/TextCell.cs | 20 ++++++++++++++++--- .../FrameworkElementColumns/TextColumn.cs | 4 +++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/client/spark/view/Controls/DIYGrid/CellRender/TextCell.cs b/src/client/spark/view/Controls/DIYGrid/CellRender/TextCell.cs index 72b52c498..882289093 100644 --- a/src/client/spark/view/Controls/DIYGrid/CellRender/TextCell.cs +++ b/src/client/spark/view/Controls/DIYGrid/CellRender/TextCell.cs @@ -20,16 +20,25 @@ namespace mbts.ui.controls { GlyphRun _glyph_run; GlyphContext _glyph_context; - static TextCell() => + static TextCell() { WPFHelper.override_metadata( HorizontalAlignmentProperty, FrameworkPropertyMetadataOptions.AffectsArrange | + FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender, (o, v) => { o._horizontal_alignment = v; o._glyph_run = null; }, HorizontalAlignment.Left); + WPFHelper.override_metadata( + WidthProperty, + FrameworkPropertyMetadataOptions.AffectsArrange | + FrameworkPropertyMetadataOptions.AffectsMeasure | + FrameworkPropertyMetadataOptions.AffectsRender, + (o, v) => o._glyph_run = null, + double.NaN); + } public TextCell() { _background = Background; @@ -162,10 +171,15 @@ namespace mbts.ui.controls { } protected override void OnRender(DrawingContext drawingContext) { + var rs = RenderSize; + var rect = new Rect(0, 0, rs.Width, rs.Height); if (_background != null) - drawingContext.DrawRectangle(_background, null, new Rect(RenderSize)); - if (_glyph_run != null) + drawingContext.DrawRectangle(_background, null, rect); + if (_glyph_run != null) { + drawingContext.PushClip(new RectangleGeometry(rect)); drawingContext.DrawGlyphRun(_foreground, _glyph_run); + drawingContext.Pop(); + } } } } diff --git a/src/client/spark/view/Controls/DIYGrid/Columns/FrameworkElementColumns/TextColumn.cs b/src/client/spark/view/Controls/DIYGrid/Columns/FrameworkElementColumns/TextColumn.cs index 6f22c40ef..0144d032b 100644 --- a/src/client/spark/view/Controls/DIYGrid/Columns/FrameworkElementColumns/TextColumn.cs +++ b/src/client/spark/view/Controls/DIYGrid/Columns/FrameworkElementColumns/TextColumn.cs @@ -22,10 +22,12 @@ namespace mbts.ui.controls { public VerticalAlignment vertical_alignment { get; set; } = VerticalAlignment.Center; public override FrameworkElement view_factory() { - var v = new TextCell { Foreground = font_brush, HorizontalAlignment = horizontal_alignment, VerticalAlignment = vertical_alignment }; + var v = new TextCell { Foreground = font_brush, VerticalAlignment = vertical_alignment }; v.SetBinding(TextCell.TextProperty, _binding); v.SetBinding(TextCell.FontFamilyProperty, new Binding(nameof(font_family)) { Source = this }); v.SetBinding(TextCell.FontSizeProperty, new Binding(nameof(font_size)) { Source = this }); + v.SetBinding(TextCell.HorizontalAlignmentProperty, new Binding(nameof(horizontal_alignment)) { Source = this }); + v.SetBinding(TextCell.WidthProperty, new Binding(nameof(ActualWidth)) { Source = this }); try_set_binding(TextCell.BackgroundProperty, background_binding); try_set_binding(TextCell.ForegroundProperty, foreground_binding); try_set_binding(TextCell.FontWeightProperty, font_weight_binding);