public DataTemplateTestViewModel(IPageDialogService pageDlg)
        {
            ItemsSource = new ObservableCollection <Person>(
                new List <Person>
            {
                new Person {
                    Name = "ABC", Days = "1,2,3,4"
                },
                new Person {
                    Name = "DEF", Days = "5,6,7,8"
                },
            }
                );

            DoCommand.Subscribe(async _ => {
                await pageDlg.DisplayAlertAsync("", "Command", "OK");
            });

            AddCommand.Subscribe(_ => {
                ItemsSource.Add(new Person {
                    Name = "Add", Days = "9,9,9,9"
                });
            });

            DelCommand.Subscribe(_ => {
                ItemsSource.Remove(ItemsSource.Last());
            });

            RepCommand.Subscribe(_ => {
                ItemsSource[0] = new Person {
                    Name = "Rep", Days = "1,1,1,1"
                };
            });

            ClrCommand.Subscribe(_ => {
                ItemsSource.Clear();
            });

            BtmCommand.Subscribe(_ => {
                ScrollToBottom.Value = true;
            });

            TopCommand.Subscribe(_ => {
                ScrollToTop.Value = true;
            });
        }
Exemple #2
0
        void InitializeProperties()
        {
            var list1 = new List <PhotoItem>();

            for (var i = 0; i < 20; i++)
            {
                list1.Add(new PhotoItem
                {
                    PhotoUrl = $"https://kamusoft.jp/openimage/nativecell/{i + 1}.jpg",
                    Title    = $"Title {i + 1}",
                    Category = "AAA",
                });
            }
            var list2 = new List <PhotoItem>();

            for (var i = 10; i < 15; i++)
            {
                list2.Add(new PhotoItem
                {
                    PhotoUrl = $"https://kamusoft.jp/openimage/nativecell/{i + 1}.jpg",
                    Title    = $"Title {i + 1}",
                    Category = "BBB",
                });
            }
            var list3 = new List <PhotoItem>();

            for (var i = 5; i < 20; i++)
            {
                list3.Add(new PhotoItem
                {
                    PhotoUrl = $"https://kamusoft.jp/openimage/nativecell/{i + 1}.jpg",
                    Title    = $"Title {i + 1}",
                    Category = "CCC",
                });
            }
            var list4 = new List <PhotoItem>();

            for (var i = 1; i < 10; i++)
            {
                list4.Add(new PhotoItem
                {
                    PhotoUrl = $"https://kamusoft.jp/openimage/nativecell/{i + 1}.jpg",
                    Title    = $"Title {i + 1}",
                    Category = "DDD",
                });
            }

            var noGroupList = new List <PhotoItem>();

            for (var i = 0; i < 20; i++)
            {
                noGroupList.Add(new PhotoItem
                {
                    PhotoUrl = $"https://kamusoft.jp/openimage/nativecell/{i + 1}.jpg",
                    Title    = $"Title {i + 1}",
                    Category = "AAA",
                });
            }
            ItemsSource2 = new PhotoGroup(noGroupList);

            var group1 = new PhotoGroup(list1)
            {
                Head = "SecA"
            };
            var group2 = new PhotoGroup(list2)
            {
                Head = "SecB"
            };
            var group3 = new PhotoGroup(list3)
            {
                Head = "SecC"
            };

            ItemsSource.Add(group1);
            ItemsSource.Add(group2);
            ItemsSource.Add(group3);
            _additionalGroup = new PhotoGroup(list4)
            {
                Head = "SEC4"
            };

            TapCommand.Subscribe(async item =>
            {
                var photo = item as PhotoItem;
                await _pageDlg.DisplayAlertAsync("", $"Tap {photo.Title}", "OK");
            });

            LongTapCommand.Subscribe(async item =>
            {
                var photo = item as PhotoItem;
                await _pageDlg.DisplayAlertAsync("", $"LongTap {photo.Title}", "OK");
            });

            var addItem = new PhotoItem
            {
                PhotoUrl = $"https://kamusoft.jp/openimage/nativecell/1.jpg",
                Title    = $"AddItem",
                Category = "AAA"
            };

            var addPtn = 0;

            AddCommand.Subscribe(_ =>
            {
                switch (addPtn)
                {
                case 0:
                    group1.Add(addItem);
                    break;

                case 1:
                    group1.Insert(0, addItem);
                    break;

                case 2:
                    group1.Insert(group1.Count / 2, addItem);
                    break;
                }

                addPtn++;
                if (addPtn > 2)
                {
                    addPtn = 0;
                }
            });

            var delPtn = 0;

            DelCommand.Subscribe(_ =>
            {
                switch (delPtn)
                {
                case 0:
                    group1.RemoveAt(0);
                    break;

                case 1:
                    group1.RemoveAt(group1.Count / 2);
                    break;

                case 2:
                    group1.RemoveAt(group1.Count - 1);
                    break;
                }
                delPtn++;
                if (delPtn > 2)
                {
                    delPtn = 0;
                }
            });

            RepCommand.Subscribe(_ =>
            {
                group1[0] = addItem;
            });

            MoveCommand.Subscribe(_ =>
            {
                group1.Move(0, 3);
            });


            AddSecCommand.Subscribe(_ =>
            {
                ItemsSource.Add(_additionalGroup);
            });

            DelSecCommand.Subscribe(_ =>
            {
                ItemsSource.RemoveAt(ItemsSource.Count - 1);
            });
        }