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

Height of Entry with data binding incorrect on UWP when Entry in ScrollView in Grid #2172

Closed
@johnshardman

Description

@johnshardman

Bug report best practices: https://github.com/xamarin/Xamarin.Forms/wiki/Submitting-Issues

Description

On complex pages on UWP, the height of Entry views can be incorrect, clipping the bottom of the text in the Entry. This occurs when the Entry uses data binding, and is in a Layout inside a ScrollView inside a Grid.

Steps to Reproduce

Using the following code with Xamarin.Forms 2.4.0.38779, push an instance of the BugUWPEntryBindingPageView page onto the navigation stack. Press the Button that appears at the top of the page and view the Entry that then appears. On UWP, the Entry is clipped.

Then, to see a nasty workaround, change the WorkaroundBug boolean to true and run again.

using System.Threading.Tasks;

using Xamarin.Forms;

namespace ViewsUsingXamarinForms
{
public class BugUWPEntryBindingViewModel : BindableObject
{
public static readonly BindableProperty ValueOneProperty
= BindableProperty.Create(
nameof(ValueOne),
typeof(string),
typeof(BugUWPEntryBindingViewModel),
default(string));

    public static readonly BindableProperty ValueTwoProperty
        = BindableProperty.Create(
            nameof(ValueTwo),
            typeof(string),
            typeof(BugUWPEntryBindingViewModel),
            default(string));

    public BugUWPEntryBindingViewModel()
    {
        ValueTwo = string.Empty;
        ValueOne = "123";
    }

    public string ValueOne
    {
        get => (string) GetValue(ValueOneProperty);

        set
        {
            if (ValueOne != value)
                SetValue(ValueOneProperty, value);
        }
    }

    public string ValueTwo
    {
        get => (string) GetValue(ValueTwoProperty);

        set
        {
            if (ValueTwo != value)
                SetValue(ValueTwoProperty, value);
        }
    }

} // public class BugUWPEntryBindingViewModel

public class BugUWPEntryBindingPageView : ContentPage
{
    private static readonly BugUWPEntryBindingViewModel ViewModel = new BugUWPEntryBindingViewModel();

    private Grid _grid;

    protected override void OnAppearing()
    {
        _grid = new Grid
        {
            BackgroundColor = Color.White,
            HorizontalOptions = LayoutOptions.Fill,
            VerticalOptions = LayoutOptions.FillAndExpand,
            ColumnDefinitions = new ColumnDefinitionCollection
            {
                new ColumnDefinition { Width = GridLength.Star },
            },
            RowDefinitions = new RowDefinitionCollection
            {
                new RowDefinition {Height = GridLength.Auto },
                new RowDefinition {Height = GridLength.Star }
            },
        };

        _grid.Children.Add(
            new Button
            {
                Text = "Add/replace entries",
                BackgroundColor = Color.Blue,
                TextColor = Color.White,
                Command = new Command(OnAddEntries)
            }, 0, 1, 0, 1);

        BindingContext = ViewModel;
        Content = _grid;
    }

    private const bool WorkaroundBug = false;
    private void OnAddEntries()
    {
        string text;
        if (WorkaroundBug)
        {
            text = ViewModel.ValueOne;
            ViewModel.ValueOne = string.Empty;
        }

        Entry entry = new Entry
        {
            FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Entry)),
        };
        entry.SetBinding(
            Entry.TextProperty,
            new Binding(
                nameof(BugUWPEntryBindingViewModel.ValueOne),
                BindingMode.TwoWay,
                null,
                string.Empty));
        _grid.Children.Add(
            new ScrollView
            {
                Content = new StackLayout
                {
                    Children =
                    {
                        entry
                    }
                }
            }, 0, 1, 1, 2);

        if (WorkaroundBug)
        {
            Task.Run(async () =>
            {
                await Task.Delay(1);
                Device.BeginInvokeOnMainThread(() =>
                {
                    ViewModel.ValueOne = text;
                });
            });
        }
    }
}

}

Expected Behavior

Expect to see "123"

Actual Behavior

Expect to see "123" but with bottom of text clipped.

Basic Information

  • Version with issue: 2.4.0.38779
  • Last known good version: N/A
  • IDE: VS2017
  • Platform Target Frameworks:
    • UWP: 14393
  • Nuget Packages: XF 2.4.0.38779
  • Affected Devices: Windows 10 x64 bit desktop

Screenshots

entry

Reproduction Link

Metadata

Metadata

Assignees

No one assigned

    Labels

    e/5 🕔5help wantedWe welcome community contributions to any issue, but these might be a good place to start!in-progressThis issue has an associated pull request that may resolve it!inactiveIssue is older than 6 months and needs to be retestedp/UWPt/bug 🐛up-for-grabsWe welcome community contributions to any issue, but these might be a good place to start!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions