I have a bound listview with a grid in the itemtemplate. The grid row's height is bound to a data property (of type GridLength) on the bound item . I can change the bound height value to anything other than zero, and it all works as expected. The row resizes to the new height. But once I set it to zero, and the row disappears as expected, even after changing the value to non-zero again, the row does not re-appear on Android (emulator. I have tried emulator version 7.1 and also 8.1 and updated Visual Studio 2017 to v. 15.9.1). On UWP it works fine. The rows re-appear as expected.
Here is a sample with two rows. When the "Hide" button is clicked, the first row height is set to zero, the second row height is set to 1. When the "Show" button is clicked, both rows are reset to their default height value. The second row resizes as expected, but the first row does not. The first row stays hidden and can not be shown again no matter what value the height is set to.
Any ideas?
<br /><?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="too young to post links"
xmlns:x="too young to post links"
xmlns:local="clr-namespace:ShowHideRow"
x:Class="ShowHideRow.MainPage">
<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>
</ContentPage>
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));
}
}
}