Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
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
Posted
Comments
[no name] 15-Oct-21 15:08pm    
Assign a width to the radio button. You're letting everything default; which doesn't always translate well from one iteration to the next.
rakeshkumar_pune 15-Oct-21 16:07pm    
I assigned the width but still it is not working. Actually this issue occurs only in IOS where as in Android it works fine.
[no name] 15-Oct-21 18:48pm    
If the line is getting truncated, it's may be from the front. A default / platform issue.
rakeshkumar_pune 17-Oct-21 23:41pm    
I have 2 columns in a row. First column is for a radiobutton and second column is for Amount. But only radiobutton is not showing up where as Amount does appear. If i click add button one more time then on the next row i see both the radibutton and Amount.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900