Ejemplo n.º 1
0
        public CardsSampleViewModel()
        {
            Items = new ObservableCollection <object>
            {
                new { Source = CreateSource(), Ind = _imageCount++, Color = Color.Red, Title = "First" },
                new { Source = CreateSource(), Ind = _imageCount++, Color = Color.Green, Title = "Second" },
                new { Source = CreateSource(), Ind = _imageCount++, Color = Color.Gold, Title = "Long Title" },
                new { Source = CreateSource(), Ind = _imageCount++, Color = Color.Silver, Title = "4" },
                new { Source = CreateSource(), Ind = _imageCount++, Color = Color.Blue, Title = "5th" }
            };

            PanPositionChangedCommand = new Command(v =>
            {
                if (IsAutoAnimationRunning || IsUserInteractionRunning)
                {
                    return;
                }

                var index = CurrentIndex + (bool.Parse(v.ToString()) ? 1 : -1);
                if (index < 0 || index >= Items.Count)
                {
                    return;
                }
                CurrentIndex = index;
            });

            RemoveCurrentItemCommand = new Command(() =>
            {
                if (!Items.Any())
                {
                    return;
                }
                Items.RemoveAt(CurrentIndex.ToCyclicalIndex(Items.Count));
            });

            GoToLastCommand = new Command(() =>
            {
                Items.Add(new { Source = CreateSource(), Ind = _imageCount++, Color = Color.Red, Title = "Other" });
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Items)));
            });
        }