2021-01-08 20:09

<TextBox TextWrapping="Wrap" ... /> hides text in some layout updates

Describe the bug

Given a TextBox, if TextWrapping is set to Wrap, HorizontalAlignment is set to Stretch, VerticalAlignment is not set to Stretch and Text is set to some text long enough so that the number of lines changes depending on its actual width, then its actual height doesn't update when a significant and sudden change to its actual width happens, at least, not always. The result is some text hidden until a user takes some action like select some text.

Steps to reproduce the bug

Steps to reproduce the behavior: 1. Create a UWP project with a single page. 2. Add a TextBox as the only child of the Page. 3. On the TextBox, set TextWrapping to Wrap and VerticalAlignment to Top. 4. Leave the rest of the properties unset. 5. Start debugging (F5). 6. Make the window's width approximately half the width of a maximized window. 7. Double click on the title bar to (suddenly) maximize the window. 8. Write a single line of text so that it almost reaches the window's width. 9. Double click on the title bar several times to change the window's width.

Expected behavior

The TextBox's actual height should always update automatically so it shows the whole text (wrapped or not).


Expected behavior: 1

Expected behavior: 2

Unexpected behavior: 3

Unexpected behavior: 4

Version Info

NuGet package version:

Microsoft.UI.Xaml 2.3.200213001

| Windows 10 version | Saw the problem? | | :--------------------------------- | :-------------------- | | November 2019 Update (18363) | Yes |

| Device form factor | Saw the problem? | | :-------------------- | :------------------- | | Desktop | Yes |

Additional context


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • weixin_39870664 weixin_39870664 3月前

    It is important that you do not hold and drag from a window's edge to switch between the maximized and non-maximized state. The bug happens right before transitioning to (or from) the two-line text box, then it readjusts accordingly to the expected behavior.

    Actually, you can hold and drag and still reproduce the bug, but you need to be very precise (1-pixel precise) to stop holding right before the transition is to occur. One thing is true, being that precise, the bug happens every single time.

    点赞 评论 复制链接分享
  • weixin_39603604 weixin_39603604 3月前

    It's likely a bug in the CTextBoxView::MeasureOverride and ArrangeOverride. We do things special for TextWrapping wrap. It looks like we probably skipped or did not ask RichEdit to redo the text layout and used the NaturalSize(GetTextNaturalSize) instead.

    点赞 评论 复制链接分享
  • weixin_39932692 weixin_39932692 3月前

    Thanks for the detailed bug report, -rod. I have tried but been unable to repro it so far. Your info includes the version of the Microsoft.UI.Xaml, but the steps from building a blank project didn't include adding its application resources - did you also do that (I tried with and without and it didn't seem to affect it, but it's worth asking)? What was the min/max tested version for your app?

    Tagging in case he's heard of a similar bug in text layout being logged internally.

    To set expectations, the layer of logic involved here would be in the core of layout, so not something that can be addressed with WinUI2. The soonest this could be addressed is after WinUI3.

    点赞 评论 复制链接分享
  • weixin_39870664 weixin_39870664 3月前


    点赞 评论 复制链接分享
  • weixin_39870664 weixin_39870664 3月前

    I've run some tests and I believe it's a race condition. In some cases, like the test above, it happens some times, whereas, in other scenarios, it happens every time.

    Anyway, in one test, I modified the TextBox's width with the aid of two buttons which increased or decreased the width by one pixel. At the threshold, the TextBox's height and/or text wrapping didn't adjust to the content as they should. Then, if the width was increased (or decreased, depending on the case) once more, the TextBox height and/or text wrapping adjusted as expected.

    点赞 评论 复制链接分享