diff --git a/src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs b/src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs index a2936f1857..4432b525ea 100644 --- a/src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs +++ b/src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs @@ -1278,7 +1278,7 @@ namespace Avalonia.Media.TextFormatting var start = GetParagraphOffsetX(width, widthIncludingWhitespace); var overhangLeading = Math.Max(0, bounds.Left - start); var overhangTrailing = Math.Max(0, bounds.Width - widthIncludingWhitespace); - var hasOverflowed = overhangLeading + widthIncludingWhitespace + overhangTrailing > _paragraphWidth; + var hasOverflowed = width > _paragraphWidth; if (!double.IsNaN(lineHeight) && !MathUtilities.IsZero(lineHeight)) { diff --git a/src/Avalonia.Controls/Documents/Inline.cs b/src/Avalonia.Controls/Documents/Inline.cs index 23b806583e..a6fe57e66e 100644 --- a/src/Avalonia.Controls/Documents/Inline.cs +++ b/src/Avalonia.Controls/Documents/Inline.cs @@ -13,9 +13,10 @@ namespace Avalonia.Controls.Documents /// /// AvaloniaProperty for property. /// - public static readonly StyledProperty TextDecorationsProperty = - AvaloniaProperty.Register( - nameof(TextDecorations)); + public static readonly AttachedProperty TextDecorationsProperty = + AvaloniaProperty.RegisterAttached( + nameof(TextDecorations), + inherits: true); /// /// AvaloniaProperty for property. @@ -43,7 +44,27 @@ namespace Avalonia.Controls.Documents get { return GetValue(BaselineAlignmentProperty); } set { SetValue(BaselineAlignmentProperty, value); } } + + /// + /// Gets the value of the attached on a control. + /// + /// The control. + /// The font style. + public static TextDecorationCollection? GetTextDecorations(Control control) + { + return control.GetValue(TextDecorationsProperty); + } + /// + /// Sets the value of the attached on a control. + /// + /// The control. + /// The property value to set. + public static void SetTextDecorations(Control control, TextDecorationCollection? value) + { + control.SetValue(TextDecorationsProperty, value); + } + internal abstract void BuildTextRun(IList textRuns); internal abstract void AppendText(StringBuilder stringBuilder); diff --git a/src/Avalonia.Controls/TextBlock.cs b/src/Avalonia.Controls/TextBlock.cs index ea420c7c45..cc92bdd752 100644 --- a/src/Avalonia.Controls/TextBlock.cs +++ b/src/Avalonia.Controls/TextBlock.cs @@ -135,7 +135,7 @@ namespace Avalonia.Controls /// Defines the property. /// public static readonly StyledProperty TextDecorationsProperty = - AvaloniaProperty.Register(nameof(TextDecorations)); + Inline.TextDecorationsProperty.AddOwner(); /// /// Defines the property. diff --git a/tests/Avalonia.Controls.UnitTests/TextBlockTests.cs b/tests/Avalonia.Controls.UnitTests/TextBlockTests.cs index eb1d6f5ea4..fd3d80729a 100644 --- a/tests/Avalonia.Controls.UnitTests/TextBlockTests.cs +++ b/tests/Avalonia.Controls.UnitTests/TextBlockTests.cs @@ -202,5 +202,26 @@ namespace Avalonia.Controls.UnitTests Assert.Equal(0, target.Inlines.Count); } } + + [Fact] + public void Setting_TextDecorations_Should_Update_Inlines() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var target = new TextBlock(); + + target.Inlines.Add(new Run("Hello World")); + + Assert.Equal(1, target.Inlines.Count); + + Assert.Null(target.Inlines[0].TextDecorations); + + var underline = TextDecorations.Underline; + + target.TextDecorations = underline; + + Assert.Equal(underline, target.Inlines[0].TextDecorations); + } + } } }