Browse Source

Merge pull request #3637 from Gillibald/fixes/TeckBlockConstraintUpdate

Invalidate TextLayout when the available size changes
Nikita Tsukanov 5 years ago
parent
commit
7489d36f9d
1 changed files with 8 additions and 3 deletions
  1. 8 3
      src/Avalonia.Controls/TextBlock.cs

+ 8 - 3
src/Avalonia.Controls/TextBlock.cs

@@ -395,7 +395,7 @@ namespace Avalonia.Controls
         /// <summary>
         /// Invalidates <see cref="TextLayout"/>.
         /// </summary>
-        protected void InvalidateFormattedText()
+        protected void InvalidateTextLayout()
         {
             _textLayout = null;
         }
@@ -412,6 +412,11 @@ namespace Avalonia.Controls
                 return new Size();
             }
 
+            if (_constraint != availableSize)
+            {
+                InvalidateTextLayout();
+            }
+
             _constraint = availableSize;
 
             return TextLayout?.Bounds.Size ?? Size.Empty;
@@ -420,13 +425,13 @@ namespace Avalonia.Controls
         protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
         {
             base.OnAttachedToLogicalTree(e);
-            InvalidateFormattedText();
+            InvalidateTextLayout();
             InvalidateMeasure();
         }
 
         private void OnTextPropertiesChanged()
         {
-            InvalidateFormattedText();
+            InvalidateTextLayout();
             InvalidateMeasure();
         }
     }