I have defined a listview and 2 buttons as follows.
<ListView x:Name="lvTest" SeparatorVisibility="None" VerticalOptions="CenterAndExpand"
HorizontalOptions="StartAndExpand" HasUnevenRows="True" BackgroundColor="#ffffff">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<RadioButton Padding="10,0,0,0" Grid.Column="0" BackgroundColor="White" TextColor="Black"
GroupName="L1" Content="{Binding Description}"
></RadioButton>
<Label Grid.Column="1" Text="{Binding Amount}" TextColor="Black" BackgroundColor="White"
HorizontalTextAlignment="End" Padding="0,0,10,0"></Label>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Button x:Name="btnAdd" Clicked="btnAdd_Clicked" Text="Add"/>
<Button x:Name="btnRemove" Clicked="btnRemove_Clicked" Text="Delete"/>
Following is the code in the codebehind class
public partial class Listview : ContentPage
{
ObservableCollection<CommonModel> temp = new ObservableCollection<CommonModel>();
CommonModel model;
public Listview()
{
InitializeComponent();
lvTest.ItemsSource = temp;
}
void btnAdd_Clicked(System.Object sender, System.EventArgs e)
{
model = new CommonModel();
model.Description = "Radio 1";
model.Amount = 100;
temp.Add(model);
}
void btnRemove_Clicked(System.Object sender, System.EventArgs e)
{
temp.RemoveAt(0);
}
}
When i run the application and click on add button the listview gets populated with a row (radiobutton and amount)
Now when i click on delete button the listview gets empty. Up till this every thing is fine.
Now if i click again on add button the listview gets populated with one row but only Amount is seen and radiobutton is missing.
Any help will be appreciated.
What I have tried:
I tried to re assign the listview itemssource property but it did not help