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

Grid height ignore change after it was set to 0 if it is in the listview. #4589

Open
Billycool1020 opened this issue Nov 30, 2018 · 1 comment
Labels
a/grid a/layout a/listview Problems with the ListView/TableView e/6 🕕 6 help wanted We welcome community contributions to any issue, but these might be a good place to start! i/low Has trivial workaround; affects very few users inactive Issue is older than 6 months and needs to be retested t/bug 🐛 up-for-grabs We welcome community contributions to any issue, but these might be a good place to start!

Comments

@Billycool1020
Copy link

Billycool1020 commented Nov 30, 2018

Description

I have a gird inside a listview. If I set the gird height to 0, then it will not show/change any more when I set the height to other value. It only happens when the gird inside a listview.

Steps to Reproduce

  1. Create a listview and grid.
    <StackLayout>
        <Button x:Name="BtnHide" Clicked="BtnHide_Clicked" Text="Hide" />
        <Button x:Name="BtnShow" Clicked="BtnShow_Clicked" Text="Show" />
        <ListView ItemsSource="{Binding BindableThings}" HasUnevenRows="True">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="{Binding BoundHeight}" />
                            </Grid.RowDefinitions>
                            <Label Grid.Row="0"  Text="{Binding TestString}" />
                        </Grid>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
  1. Set the BindingContext and set button click event. In the click event change the grid height.
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
            this.BindingContext = this;
        }

        public List<BindableThing> BindableThings { get; set; } = new List<BindableThing>()
        {
            new BindableThing() { TestString = new String ('*', 200)  },
            new BindableThing() { TestString = new String ('!', 200)  },
        };

        private void BtnHide_Clicked(object sender, EventArgs e)
        {
            BindableThings[0].BoundHeight = new GridLength(0);
            BindableThings[1].BoundHeight = new GridLength(1);
        }

        private void BtnShow_Clicked(object sender, EventArgs e)
        {
            BindableThings[0].BoundHeight = new GridLength(50);
            BindableThings[1].BoundHeight = new GridLength(50);
        }
    }

    public class BindableBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public void propchg(string propname)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propname));
        }
    }

    public class BindableThing : BindableBase
    {
        public string TestString { set; get; }
        GridLength _BoundHeight = new GridLength(50);
        public GridLength BoundHeight {
            get => _BoundHeight;
            set {
                _BoundHeight = value;
                propchg(nameof(BoundHeight));
            }
        }
    }

Expected Behavior

Click BtnHide the grid hide and click BtnShow the grid show.

Actual Behavior

Click BtnHide the grid hide and click BtnShow the first grid which height is set to 0 not show.

Basic Information

  • Version with issue: Xamarin.Forms 3.3.0.967583
  • Last known good version:
  • IDE: Visual Studio 2017 enterprise 15.9.3
  • Platform Target Frameworks:
    • Android: 8.1
@Billycool1020 Billycool1020 changed the title Gird height ignore change after it was set to 0, if it is in the listview. Gird height ignore change after it was set to 0 if it is in the listview. Nov 30, 2018
@StephaneDelcroix StephaneDelcroix changed the title Gird height ignore change after it was set to 0 if it is in the listview. Grid height ignore change after it was set to 0 if it is in the listview. Nov 30, 2018
@samhouts samhouts added a/listview Problems with the ListView/TableView t/bug 🐛 e/6 🕕 6 i/low Has trivial workaround; affects very few users labels Nov 30, 2018
@PureWeen
Copy link
Contributor

PureWeen commented Dec 5, 2018

Here's a reproduction / work around for the issue

RowHeightWithBinding.zip

Basically I'm just calling ForceUpdateSize on the view cell after the height is changed which causes it to remeasure correctly. It looks like Xamarin Forms isn't properly detecting the change on Grid layout and causing its own internal ForceUpdateSize

@samhouts samhouts added inactive Issue is older than 6 months and needs to be retested help-wanted up-for-grabs We welcome community contributions to any issue, but these might be a good place to start! help wanted We welcome community contributions to any issue, but these might be a good place to start! and removed help-wanted labels Jun 25, 2019
@samhouts samhouts added this to the 5.0.0 milestone Aug 13, 2020
@samhouts samhouts removed this from the 5.0.0 milestone Nov 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/grid a/layout a/listview Problems with the ListView/TableView e/6 🕕 6 help wanted We welcome community contributions to any issue, but these might be a good place to start! i/low Has trivial workaround; affects very few users inactive Issue is older than 6 months and needs to be retested t/bug 🐛 up-for-grabs We welcome community contributions to any issue, but these might be a good place to start!
Projects
None yet
Development

No branches or pull requests

4 participants