Press ESC to close

Xamarin Forms Refreshing List

As we work with our mobile applications, we need to be updated and renewed whenever we want. The best control we can show regularly on our data is the ListView control. In this article, we will talk about how to update our objects that are also in our ListView.

First you need to have our objects in the ListView. Later, we need to give ListView a few properties. We need to allow these features to be refreshed when the list is pulled down. Then we write the function we need to write about what will happen in the refresh process. The last thing we will do is to stop the renewal, ie the update icon. I am doing the first of these transactions. I let you regenerate when pulled down.

 <StackLayout>
                <ListView x:Name="cisimListe"
                          ItemsSource="{Binding .}"
                          IsPullToRefreshEnabled="True">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <ViewCell.View>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*"/>
                                            <ColumnDefinition Width="Auto"/>
                                        </Grid.ColumnDefinitions>
                                        <Label Text="{Binding CisimAdi}"
                                           HorizontalOptions="Center"
                                               Grid.Column="0"
                                           VerticalOptions="Center"
                                           HorizontalTextAlignment="Center"
                                           VerticalTextAlignment="Center"
                                           FontAttributes="Bold"
                                           FontSize="Medium"
                                           TextColor="Blue"/>
                                        <Button Grid.Column="1"
                                                Text="Sil"
                                                BackgroundColor="Red"
                                                TextColor="White"
                                                x:Name="buttonSil"
                                                Clicked="buttonSil_Clicked"
                                                CommandParameter="{Binding .}"/>
                                    </Grid>
                                </ViewCell.View>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackLayout>

Then I write the function that allows me to write what happens when the list is updated. What you have to do for this is say “+ =”. Press the tab key. Visual Studio will automatically create the function. Then we come into function. The first thing we need to do here is; uncover the regeneration symbol. The second step is to re-export the data to the list. What I do right now is to let the user know that the listen has been refreshed, and the last thing to do is stop the refresh.

public AnaSayfaMaster ()
	{
			InitializeComponent ();
            manager = new VeriTabaniYonetici();
            cisimListe.Refreshing += CisimListe_Refreshing;
            Listele();
	}

        private void CisimListe_Refreshing(object sender, EventArgs e)
        {
            cisimListe.IsRefreshing = true;
            Listele();
            DisplayAlert("Başarılı", "Liste başarıyla yenilendi", "OK");
            cisimListe.IsRefreshing = false;
        }

If you have any questions, you can reach us by email or comment.

Leave a Reply

Your email address will not be published. Required fields are marked *