Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextBox TextWrapping WrapWholeWords causes xml parsing exception #4199

Open
nzstevem opened this issue Feb 15, 2021 · 9 comments
Open

TextBox TextWrapping WrapWholeWords causes xml parsing exception #4199

nzstevem opened this issue Feb 15, 2021 · 9 comments
Labels
area-Parser area-TextBox TextBox, RichEditBox bug Something isn't working feature proposal New feature proposal product-winui3 WinUI 3 issues team-Markup Issue for the Markup team

Comments

@nzstevem
Copy link

Describe the bug
Simple MainWindow XML code as follows. NO code behind. When run in VS generated XML parsing exception.

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="400"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="400"/>
    </Grid.ColumnDefinitions>
    <Border Grid.Column="0" BorderBrush="Aqua" BorderThickness="2" Margin="4" HorizontalAlignment="Center" VerticalAlignment="Top">
        <TextBox TextWrapping="Wrap" Text="# Column ZERO Column ZERO Column ZERO Column ZERO Column ZERO #"/>
    </Border>
    <Border Grid.Column="1" BorderBrush="Aqua" BorderThickness="2" Margin="4" HorizontalAlignment="Center" VerticalAlignment="Top">
        <TextBox TextWrapping="WrapWholeWords" Text="# Column ONE Column ONE Column ONE Column ONE Column ONE Column ONE Column ONE Column ONE Column ONE Column ONE Column ONE Column ONE #"/>
    </Border>
    <Border Grid.Column="2" BorderBrush="Aqua" BorderThickness="2" Margin="4" HorizontalAlignment="Center" VerticalAlignment="Top">
        <TextBox TextWrapping="Wrap" Text="# Column TWO Column TWO Column TWO Column TWO Column TWO Column TWO #"/>
    </Border>
</Grid>

Steps to reproduce the bug

  1. Create a new WinUI Desktop app.
  2. Replace MainWindow XAML with the above. Note "WrapWholeWords" on center col TextBox.
  3. Run the app in VS and it will crash. See screen shot.
  4. Changing "WrapWholeWords" to simply "Wrap" and the exception doesn't occur. The Wrap option actually wraps whole words rather than splitting words which might be a bug as well.

Expected behavior
Expected the app to run and demonstrate resizing and re-wrapping of center column.

Also noticed that when the app is run with the center column TextWrapping="Wrap" that the TextBox and Border shrink as the page window is reduced as expected. But when the window is then expanded back the center Border/TextBox does not expand back to its original size.

Screenshots

Exception screen...
image

Running app with WrapWholeWords changed to Wrap looks as expected
image

Second image after window reduced in width and then expanded - the center TextBox doesn't re-size and re-wrap????
image

Version Info
Edition Windows 10 Pro
Version 20H2
Installed on ‎16/‎07/‎2020
OS build 19042.804
Experience Windows Feature Experience Pack 120.2212.551.0

NuGet package version:
[Microsoft.WinUI 3.0.0-preview4.210210.4]
-->

Windows app type:

UWP Win32
Windows 10 version Saw the problem?
October 2020 Update (19042)
Device form factor Saw the problem?
Desktop

Additional context

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Feb 15, 2021
@StephenLPeters StephenLPeters added version-winui3preview4 WinUI 3 Preview 4 issues team-Markup Issue for the Markup team product-winui3 WinUI 3 issues labels Feb 17, 2021
@StephenLPeters
Copy link
Contributor

@RealTommyKlein and @fabiant3 FYI

@nzstevem is this issue exclusive to Preview4?

@StephenLPeters StephenLPeters added the needs-author-feedback Asked author to supply more information. label Feb 17, 2021
@nzstevem
Copy link
Author

I'm not absolutely sure if the issue was introduced with Preview4 but I think NOT. From memory I applied PV4 thinking that might clear the issue. Now I've installed PV4 in VS I'm not sure how to go back.

@ghost ghost removed the needs-author-feedback Asked author to supply more information. label Feb 17, 2021
@codendone
Copy link
Contributor

The error message could definitely be better, but WrapWholeWords is an unsupported value for TextBox. From TextBox.TextWrapping docs:

TextBox and RichEditBox don't support the WrapWholeWords value for their TextWrapping properties. If you try to use WrapWholeWords as a value for TextBox.TextWrapping or RichEditBox.TextWrapping, an exception is thrown.

@nzstevem
Copy link
Author

The situation is made worse by the fact that VS doesn't complain during either edit or build.

I've struck a number of issues of this type where code flies through VS intellisense and then build and then fails during execution with an error message that gives no clue as to where the issue lies.

Even in code the TextWrapping Enum includes the WrapWholeWords item. Perhaps it needs a TextBoxTextWrapping Enum to avoid confusion with TextBlock.

image

It took me hours to work out what was causing the issue. Given it had sailed through VS I immediately assumed it was a library/version issue or a bug. After messing around and updating to very latest I then started peeling out options and eventually found by a process of elimination what was triggering the error. These sort of issues are a real headache when you are still trying to get to grips with the framework as I am.

BUT...

The real confusion here is that TextWrapping="Wrap" actually wraps whole words! it does NOT character wrap!!!!

image

So why WholeWords is not supported when Wrap does just this is confusing. It is Character wrap that is not supported!

@codendone codendone added area-TextBox TextBox, RichEditBox team-Framework and removed team-Markup Issue for the Markup team labels Mar 26, 2021
@codendone
Copy link
Contributor

You're right, it does seem like it should reject Wrap rather than WrapWholeWords. It could probably also be argued that it should just accept either value even if it only wraps as whole words currently -- that might be better than rejecting a value only via exception at runtime.

@nzstevem
Copy link
Author

I would have thought an option to just wrap at a character level with no sensitivity to "words" or spaces would be a simple and obvious first option.

The more complex option (which appears to be what we have) is to wrap on word boundaries. I note in a TEXTBLOCK with the WrapWholeWords option when the word won't fit on its own line it truncates the long word and the next line starts with the next word. You wouldn't want to be keying into a TextBox and not be able to see what you entered! So this option might be better named "OnlyWrapAtWordEnd".

A TextBox WrapWholeWords needs to wrap on space when it can but be prepared to character wrap when there is no other choice.

This is like a lot of things. More complex the longer you look at it! :-)

@chrisglein chrisglein added area-Parser feature proposal New feature proposal and removed needs-triage Issue needs to be triaged by the area owners version-winui3preview4 WinUI 3 Preview 4 issues labels Jul 21, 2021
@knightmeister
Copy link

This is still an issue as of the current version of WinUI3 (via Windows App SDK)

@bpulliam bpulliam added team-Markup Issue for the Markup team and removed team-Framework labels Aug 22, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Aug 22, 2023
@bpulliam bpulliam removed the needs-triage Issue needs to be triaged by the area owners label Oct 18, 2023
@duncanmacmichael duncanmacmichael added the bug Something isn't working label Nov 3, 2023
@cmonto
Copy link

cmonto commented Nov 6, 2023

Its totally unacceptable that a simple character wrap is not possible in WinUI ATM. The TextWrapping.Wrap does word wrap wasting a lot of space and TextWrapping.WrapWholeWords does a miserable wrap. Just see below to believe this is the same multi line TextBlock with WordEllipsis and same Text.. only the TextWrapping property changed:

Wrap

WrapWholeWords

@Abe-Froman
Copy link

Just found this open issue, glad too but I wasted about an hour trying to debug this XAML parsing error before finding it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Parser area-TextBox TextBox, RichEditBox bug Something isn't working feature proposal New feature proposal product-winui3 WinUI 3 issues team-Markup Issue for the Markup team
Projects
None yet
Development

No branches or pull requests

9 participants