Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Collection View Binding is not getting updated on page load

$
0
0

Hi,

Greetings!

I have a checkbox which should be checked With selected values from the DB on Page Load. I have azure mobile Service client in backend and after the DB call, I am updating the observable collection binded to the Collection view that contains the check box. But on Page load check box is not getting checked as the query returns the result lately. when I keep the breakpoint before load for couple of seconds then the page loads with checkbox checked.

How do I add the delay or bind the collection appropriately to have the desired result.

Code which is marking the Is checked to True.

public ItemUpdate()
        {
            InitializeComponent();
        GetCheckboxAsync();
            listview.ItemsSource = ivm.ItemValues;
        }

        protected override void OnAppearing()
        {
            base.OnAppearing();
            BindingContext = ivm;

        }
public async void GetCheckboxAsync()
        {

            Itemcat = await App.client.GetTable<Item_Categories>().Where(x => x.HotelId == App.HotelId && x.ItemName == Item.ItemName).ToListAsync();

            foreach (var itemcategoryname in Itemcat)
            {
                int i = 0;
                foreach (var item in ItemValue)
                {
                    item.ItemName = itemcategoryname.ItemName;
                    item.id = itemcategoryname.id;

                    if (item.ItemCategory == itemcategoryname.ItemCategory)
                    {
                       ItemValue[i].IsChecked = true;
                    }
                    i = i + 1;
                }
            }
        }

Observable collection:

public ObservableCollection<Item_Categories> _ItemValue = new ObservableCollection<Item_Categories>();
        public ObservableCollection<Item_Categories> ItemValue
        {
            get
            {
                return _ItemValue;

            }
            set
            {
                if (_ItemValue != value)
                {
                    _ItemValue = value;
                }
                NotifyPropertyChanged();
            }
        }

Above Observable collection is bonded to collection view of the checkbox

CollectionView x:Name="listview" ItemsSource="{Binding ItemValue}"

CollectionView x:Name="listview" ItemsSource="{Binding ItemValue}"
                        CollectionView.ItemTemplate
                            DataTemplate
                                    StackLayout Orientation="Horizontal" Padding="5,0,5,0"
                                        CheckBox x:Name="CheckBoxValue"  Color="White" BackgroundColor="YellowGreen"  HeightRequest="40"
                                                  IsChecked="{Binding IsChecked}" CheckedChanged="CheckBox_CheckedChanged"
                                        Label Text="{Binding ItemCategory}" HorizontalOptions="StartAndExpand"
                                            Label.GestureRecognizers
                                                TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"
                                            Label.GestureRecognizers
                                            Label
                                    StackLayout
                            DataTemplate
                        CollectionView.ItemTemplate
 CollectionView

Regards,
Mahesh B


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>