xamarin/Xamarin.Forms
Grid height ignore change after it was set to 0 if it is in the listview.
Open
#4,589 opened on Nov 30, 2018
a/grida/layouta/listviewe/6 :clock6:help wantedi/lowinactivet/bug :bug:up-for-grabs
Repository metrics
- Stars
- (5,644 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
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
- 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>
- 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