0
votes

I tried in either of the ways to bind 2 list views using MVVVM but, couldn't able to do that. While I'm calling 2 property with same API with 2 different models, it is asking me to call await function. But I want both the property to fetch API at a time.

namespace Grading.ViewModel
{
    public class GradingViewModel
    {
        private ObservableCollection<GradingModel> items;

        public ObservableCollection<GradingModel> Items
        {
            get { return items; }
            set
            {
                items = value;
            }
        }

        public GradingViewModel()
        {
            Items = new ObservableCollection<GradingModel>()
            {

            };
            MyHTTP.GetAllNewsAsync(list =>
            {
                foreach (GradingModel item in list)
                    items.Add(item);
            });

        }

        public Details()
        {
            Items = new ObservableCollection<Details>()
            {

            };
            MyHTTP.GetAllNewsAsync(list =>
            {
                foreach (Details info in list)
                    Info.Add(info);
            });

        }

    }
}
1
If you want to bind the listview or any from ViewModel to Xaml you should use interface property 'INotifyPropertyChanged' - Prasanth
Hi,why want both the property to fetch API at a time? Items be setted twice at a time maybe not a good logic. You can show more info about project. - Junior Jiang

1 Answers

1
votes

If you want to use multiple parallel HTTP calls then you have to use threading

var t1 = //first req
var t2 = //Second reg

await Task.WhenAll(t1, t2);

ApiResponse response1 = t1.Result;
if (response1.IsSuccess)
{
    //Success code
}

ApiResponse response2 = t2.Result;
if (response2.IsSuccess)
{
    //Success code
}