Forum Xamarin.Forms

Binding two collection view

daalboodaalboo Member ✭✭✭

I have a horizontal collection view that act as tabbed menu and change items of Vertical collection view. My current approach is to clear all items from horizontal collection view and add items again. I cleared all items but couldn't add new items. Here is my viewmodel code.

 public class courseListViewModel : INotifyPropertyChanged
    {
        readonly IList<course> source2;
        readonly IList<listing> source3;
        public ObservableCollection<course> CoursePreview { get; private set; }
        public ObservableCollection<listing> itemPreview2 { get; private set; }
        public ICommand TapCommand { get; set; }
        public ICommand CourseTapCommand { get; set; }

        public  courseListViewModel()
        {
            source3 = new List<listing>();
            source2 = new List<course>();
            CreateCourseCollection();
            CreateCategoryCollection();
            TapCommand = new Command<listing>(items =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {                   
                    CoursePreview.Clear();
                    //OnPropertyChanged();
                    CreateCourseCollection2();
                });


            });
        }
 void CreateCategoryCollection()
        {
            source3.Add(new listing
            {
                ImageUrl = "education",
                title = "All",
                number = "2 COURSE"
            });
            source3.Add(new listing
            {
                ImageUrl = "technology",
                title = "Computer Learning",
                number = "2 COURSE"
            });

            itemPreview2 = new ObservableCollection<listing>(source3);
        }
        void CreateCourseCollection()
        {
            source2.Add(new course
            {
                ImageUrl = "course",
                noofCourse = "5 Lessions",
                title = "Introduction to C Programming",
                type = "Paid Lession",
                teacherName = "ABC Teacher",
                price = "100"
            });

            source2.Add(new course
            {
                ImageUrl = "course",
                noofCourse = "5 Lessions",
                title = "Introduction to C Programming",
                type = "Paid Lession",
              teacherName = "ABC Teacher",
                price = "100"
            });
            CoursePreview = new ObservableCollection<course>(source2);
        }

        void CreateCourseCollection2()
        {

            source3.Add(new listing
            {
                ImageUrl = "education",
                title = "Java",
                number = "5 COURSE"
            });
            itemPreview2 = new ObservableCollection<listing>(source3);
        }
        #region INotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;

        void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion
    }

How can I update items for listview/collectionview from another collectionView/Listview?

Sign In or Register to comment.