xamarin/Xamarin.Forms

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

開放

#4,589 建立於 2018年11月30日

 (1 則留言) (0 個反應) (0 位負責人)C# (1,926 個分叉)batch import
a/grida/layouta/listviewe/6 :clock6:help wantedi/lowinactivet/bug :bug:up-for-grabs

倉庫指標

星標
 (5,644 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

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

貢獻者指南