Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] Entry text initially invisible on UWP #8787

Closed
squinn7 opened this issue Dec 6, 2019 · 49 comments · Fixed by #11140
Closed

[Bug] Entry text initially invisible on UWP #8787

squinn7 opened this issue Dec 6, 2019 · 49 comments · Fixed by #11140
Labels
4.3.0 regression on 4.3.0 e/3 🕒 3 i/regression in-progress This issue has an associated pull request that may resolve it! m/high impact ⬛ p/UWP t/bug 🐛

Comments

@squinn7
Copy link

squinn7 commented Dec 6, 2019

Description

On UWP, with a certain combination of views and layouts, there is a circumstance where text in an entry will initially be invisible. This can be remedied in the app by resizing the windows or clicking into the entry. Based on my investigation, there seems to be an issue where the the actual element that holds the text in UWP is not full size.

We also observed a similar but not quite the same issue when there are entries in a List View in a view cell where the text will not appear unless the cursor is brought near the entry. I don't have a repro for this yet but I bring it up because it might be related.

Finally, while I was able to make it appear by setting a height request, the behavior is not quite predictable. In our production apps, setting/not setting height requests was not able to change anything. In our production apps, we fixed it by setting a width request of 5 which for some reason resolved it in our environment.

Steps to Reproduce

Repro project below

Expected Behavior

Text should appear initially upon page load as it does on Android and iOS.

Actual Behavior

The text is not initially visible in entries unless they are resized or interacted with.

Basic Information

  • Version with issue: 4.3.0.991221 (any version after the last known good one)
  • Last known good version: 4.2.0.848062
  • IDE: 16.4.0
  • Platform Target Frameworks:
    • UWP: 1903, 18362
  • Nuget Packages: Xamarin Forms 4.3.0.991221,
    Microsoft.NETCore.UniversalWIndowsPlatform 6.2.9,
    Xamarin.Essentials 1.3.1

Screenshots

Issue on UWP,
entryIssue

Issue not present on iOS as an example,
image

Reproduction Link

https://github.com/squinn7/EntryBindingRepro

@squinn7 squinn7 added s/unverified New report that has yet to be verified t/bug 🐛 labels Dec 6, 2019
@bmacombe
Copy link
Contributor

bmacombe commented Dec 7, 2019

#8214 might resolve this. I noticed similar when testing for that PR

@WayaFlyfeather
Copy link
Contributor

#8214 might resolve this. I noticed similar when testing for that PR

@bmacombe I'd guess it is (also?) related to #8503, and hopefully fixed in #8536. I don't know if we have been working on the same symptom(?)

@Russc0
Copy link

Russc0 commented Dec 8, 2019

Yes I've also noticed this happening since the latest Xamarin Forms version.

@squinn7 squinn7 changed the title [Bug] Entry text initally invisible on UWP [Bug] Entry text initiallyinvisible on UWP Dec 8, 2019
@squinn7 squinn7 changed the title [Bug] Entry text initiallyinvisible on UWP [Bug] Entry text initially invisible on UWP Dec 8, 2019
@bmacombe
Copy link
Contributor

bmacombe commented Dec 8, 2019

@WayaFlyfeather I took the changes from #8536 and made them to #8214 to see if they resolved the issue I was attempting to resolve.

Without 8536, this is how the issue page 2172 looks without applying style changes. The green section is with the 2172 renderer changes and the red is with the unmodified renderer.
image

With 8536, it seems to cause two text boxes that worked correctly with 8214 to regress and it does fix most of the boxes in the red, but not the auto size editor.
image

I think it's safe to say there is something strange going on with FormsTextBox that we all haven't exactly nailed down yet. I tried to reproduce the 2172 issues with stock UWP and couldn't

@Brosten
Copy link

Brosten commented Dec 11, 2019

I'm encountering the same issue. Please fix asap.
What is the best workaround?

@sude22
Copy link

sude22 commented Dec 11, 2019

Same problem here. I can not update to 4.3 until this is fixed.

@Xyotic
Copy link

Xyotic commented Dec 12, 2019

I noticed this behavior if you change the Text while the Entry is hidden.
Theres also a simmilar issue with switches.
See: #8854

@samhouts samhouts added 4.3.0 regression on 4.3.0 i/regression e/3 🕒 3 labels Jan 3, 2020
@jsiemens
Copy link

jsiemens commented Jan 6, 2020

Same issue here. Also looking for a workaround...

@jsiemens
Copy link

jsiemens commented Jan 7, 2020

I've come up with a workaround. Here you go:


namespace App1
{
    public class CustomEditor : Editor
    {
        public CustomEditor()
        {
        }
    }
}


[assembly: ExportRenderer(typeof(CustomEditor), typeof(UwpEditorRenderer))]
namespace App1.UWP
{
    class UwpEditorRenderer : EditorRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Editor> e)
        {
            base.OnElementChanged(e);
            if (e.OldElement != null)
            {
                Control.Loaded -= Control_Loaded;
            }
            if (e.NewElement != null)
            {
                Control.Loaded += Control_Loaded;
            }
        }

        private void Control_Loaded(object sender, RoutedEventArgs e)
        {
            // Hack workaround for: https://github.com/xamarin/Xamarin.Forms/issues/8787
            Control.Text = string.Empty;
            Control.Text = Element.Text;
            Control.Loaded -= Control_Loaded;
        }
    }
}

@Brosten
Copy link

Brosten commented Jan 29, 2020

Thanks @jsiemens for the work around. To make it work for Entry Controls (as the bug describes) I just changed the renderer to an EntryRenderer.

Also needed some additional null checks, ended up with

 public class UwpEditorRenderer : EntryRenderer
   {
      protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
      {
         base.OnElementChanged(e);
         if (e.OldElement != null && Control != null)
         {
            Control.Loaded -= Control_Loaded;
         }
         if (e.NewElement != null && Control != null)
         {
            Control.Loaded += Control_Loaded;
         }
      }

      private void Control_Loaded(object sender, RoutedEventArgs e)
      {
         // Hack workaround for: https://github.com/xamarin/Xamarin.Forms/issues/8787
         Control.Text = string.Empty;
         Control.Text = Element?.Text ?? string.Empty;
         Control.Loaded -= Control_Loaded;
      }
   }

But XF-team, please fix!

@mathiasjakob
Copy link

I've tried the workaround and it works fine for short strings. But if the string is long and needs to be wrapped, the text is not displayed, and it is only displayed when you resize the window.

Without the workaround, short texts are not displayed, but long texts that need to be wrapped are.

@mathiasjakob
Copy link

mathiasjakob commented Jan 29, 2020

I've updated the workaround so that it also works with strings that have to be wrapped:

protected override void OnElementChanged (ElementChangedEventArgs<Editor> e) 
{
    base.OnElementChanged (e);

    if (Control == null) { return; }

    if (e.OldElement != null && Control != null) 
    {
        Control.Loaded -= Control_Loaded;
    }
    if (e.NewElement != null && Control != null) 
    {
        Control.IsEnabled = true;
        Control.Loaded += Control_Loaded;
    }
}

private void Control_Loaded (object sender, RoutedEventArgs e) 
{
    // Hack workaround for: https://github.com/xamarin/Xamarin.Forms/issues/8787
    Control.Text = string.Empty;
    Control.Text = Element?.Text ?? string.Empty;
    Control.Loaded -= Control_Loaded;
}


Although Control.IsEnabled is set to true, the editor on the page is still disabled.
Shouldn't this actually cause the editor to be enabled?

@jsiemens
Copy link

jsiemens commented Jan 29, 2020

In case it helps anyone, I did find that my originally solution didn't always work. I settled on the following approach which has proven to work 100% of the time as tested. This is specifically for Editor, rather than Entry, so the existing workaround for Entry may be reliable, and this code is specifically looking for a certain named element within the control template so it wouldn't work for Entry although something similar could maybe be done.

    private async void Control_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
    {
        // Hack workaround for: https://github.com/xamarin/Xamarin.Forms/issues/8787
        Control.Loaded -= Control_Loaded;
        await Task.Delay(1);
        var content = (UIElement) Control.FindName("ContentElement");
        Control.Foreground = new SolidColorBrush(Element.TextColor.ToWindowsColor());
    }

@bmacombe
Copy link
Contributor

Hey @samhouts I think this issue was closed by accident, #11140 did fix this until #11350 was merged, hopefully, #11351 will fix if that solution is approved.

@samhouts samhouts reopened this Jul 13, 2020
@samhouts
Copy link
Member

Yep, GitHub got a little excited. Thanks, @bmacombe !

@sude22
Copy link

sude22 commented Jul 17, 2020

This bug prevents me to update my project for nearly six month. It would be really a pleasure if it could be solved in the next service release. Thank you.

@bmacombe
Copy link
Contributor

@sude22 There is a PR open to address this #11351 in the review process.

@mhrastegari
Copy link
Contributor

@sude22 i think it fixed in 4.8 pre1 because my editor finally works fine

@bmacombe
Copy link
Contributor

#11140 which is in 4.8 and the latest 4.7 SR I believe partially fixed the text visibility problem on UWP. It really depends on your layout if it was or not. You could still have problems currently if you have a really nested layout.

@sude22
Copy link

sude22 commented Jul 19, 2020

With V4.7.0.1142+463-sha.333e71c12-azdo.3888487 I still have the problem.

@bmacombe
Copy link
Contributor

@sude22 and everyone else on this issue, Thanks to some help from @PureWeen #11351 was merged into 4.7 today. Hopefully, we'll see it in the next 4.7 SR

@JKennedy24
Copy link

Do we think this will be in the next 4.7.0 SR or shal I implement the workaround from here: #8787 (comment)

@sude22
Copy link

sude22 commented Jul 26, 2020

For me, this issue seems to be fixed in 4.7.0.1179.

@samhouts
Copy link
Member

closed by #11351

@cmpalmer66
Copy link

I'm seeing this problem again in v4.8.0.1269, had to re-activate the workaround above to get the values to show on UWP.

@gceaser
Copy link

gceaser commented Aug 13, 2020

For me v4.8.0.1269 is the first release to fix the problem.

@cmpalmer66
Copy link

For me v4.8.0.1269 is the first release to fix the problem.

Hmm. I had a form with several Entry boxes (IsEnabled="false" on them to make them read only, if that matters). I set their bound property in the VM and on iOS, the values appear. On UWP, they did not appear. I turned on the fix above with the EntryRenderer (we'd implemented it when we saw this problem before, but had since disabled it) and the values started appearing on UWP as they were on iOS.

@bmacombe
Copy link
Contributor

bmacombe commented Aug 13, 2020

@cmpalmer66 Can you create a repro project? I just pulled the 4.8 branch and tested all the test pages and everything still looks good.

@bmacombe
Copy link
Contributor

If you can, probably best to create a new issue also since this one was closed.

@cmpalmer66
Copy link

I will try. Maybe it's a coincidence or glitch, but I'll see what I can do and create a new issue if I can duplicate.

@bmacombe
Copy link
Contributor

If you do, ping me on it and I'll try to take a look. I want to squash all these UWP not showing until resizing issues, they are driving me nuts too!

@pauldiston
Copy link

Should this issue be reopened or is there a build of XF that has fixed this issue?

@valerii-sovytskyi
Copy link

Guys, this is the solution that works for me 100% but none of the above, my XF version 4.7.0.1351
After 50ms await just update the layout.
Do not need to reset the text as the main problem of the inner height of the TextBox

    private async void Control_LoadedOnElementChanged(object sender, RoutedEventArgs e)
    {
        if (!string.IsNullOrEmpty(Element.Text) && Control != null)
        {
            // HACK: Entry text initially invisible. See Url: https://github.com/xamarin/Xamarin.Forms/issues/8787
            await Task.Delay(50);

            Control.UpdateLayout();
            Control.Loaded -= Control_LoadedOnElementChanged;
        }
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
4.3.0 regression on 4.3.0 e/3 🕒 3 i/regression in-progress This issue has an associated pull request that may resolve it! m/high impact ⬛ p/UWP t/bug 🐛
Projects
None yet