コード例 #1
0
        public virtual void MoveToTopSelectedItem()
        {
            if (Items == null || !Items.Any())
            {
                return;
            }

            foreach (var i in Items)
            {
                i.IsSelectedItemForView = false;
            }

            if (!SelectedItemIsNull)
            {
                SelectedItem.IsSelectedItemForView = true;
            }

            var item = SelectedItem;

            var notSelected = Items.Where(x => !x.IsSelectedItemForView).ToList();

            Items.Clear();
            Items.Add(item);
            Items.AddRange(notSelected);

            SelectedItem = item;

            Notify(nameof(Items));
            CreateNewCommand?.NotifyCanExecuteChanged();
        }
コード例 #2
0
        public FileCommands(Func <T> onCreate, Func <IStorageFile, Task <T> > loadFile, Func <IStorageFile, Task> saveFile, string[] loadExtensions, IEnumerable <KeyValuePair <string, IList <string> > > saveExtensions)
        {
            this.loadExtensions = loadExtensions;
            this.saveExtensions = saveExtensions;

            CreateNewCommand = ReactiveCommand.Create(onCreate);

            CreateFromExistingCommand = ReactiveCommand.CreateFromObservable(() => Observable.FromAsync(PickFileToOpen)
                                                                             .Where(f => f != null)
                                                                             .SelectMany(loadFile));

            Objects = CreateNewCommand.Merge(CreateFromExistingCommand);

            SaveFileCommand = ReactiveCommand.CreateFromTask(async() =>
            {
                var file = await PickFileToSave();
                if (file != null)
                {
                    await saveFile(file);
                }
            }, CreateFromExistingCommand.Any());

            IsBusy = CreateFromExistingCommand.IsExecuting.Merge(SaveFileCommand.IsExecuting);

            CreateFromExistingCommand.ThrownExceptions.Subscribe(exception => { });
            SaveFileCommand.ThrownExceptions.Subscribe(exception => { });
        }
コード例 #3
0
 public virtual void ClearItems()
 {
     if (Items != null && AnyItem())
     {
         Items.Clear();
         Notify(nameof(Items));
         CreateNewCommand?.NotifyCanExecuteChanged();
     }
 }
コード例 #4
0
 public virtual void Remove(T item)
 {
     if (Items != null && AnyItem())
     {
         Items.Remove(item);
         SelectedItem = Items.FirstOrDefault();
         Notify(nameof(Items));
         CreateNewCommand?.NotifyCanExecuteChanged();
     }
 }
コード例 #5
0
 public virtual void AddItem(T item)
 {
     if (Items != null)
     {
         Items.Add(item);
         SelectedItem = item;
         Notify(nameof(Items));
         CreateNewCommand?.NotifyCanExecuteChanged();
     }
 }
コード例 #6
0
 public virtual void RemoveEmptyItems()
 {
     if (Items != null)
     {
         var data = Items.Where(x => x.Id == 0).ToList();
         foreach (var d in data)
         {
             Items.Remove(d);
         }
         CreateNewCommand?.NotifyCanExecuteChanged();
     }
 }
コード例 #7
0
 public ExtendedSplashScreenViewModel(IMvxNavigationService navigationService)
 {
     CreateCommand = new CreateNewCommand(navigationService);
 }
コード例 #8
0
 public void Refresh()
 {
     Notify(nameof(Items));
     CreateNewCommand?.NotifyCanExecuteChanged();
 }
コード例 #9
0
        private void LoadCommands()
        {
            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
            {
                var imageDefinition = await _imageLoadTask.PickThumbnailImage();

                return(imageDefinition);
            });

            LoadCommand.Subscribe(LoadThumbnailImage);

            SnapCommand = ReactiveCommand.CreateAsyncTask(async _ =>
            {
                var camera = new CameraCaptureUI();

                var file = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo);

                return(await _imageLoadTask.GetImageDefinitionFromFile(file));
            });

            SnapCommand.Subscribe(LoadThumbnailImage);

            SaveCommand =
                ReactiveCommand.Create(this.WhenAny(x => x.PlayerDetails.IsDirty, x => x.PlayerDetails.Name,
                                                    x => x.PlayerDetails.NickName,
                                                    (isDirty, name, nickName) =>
                                                    isDirty.Value && !string.IsNullOrWhiteSpace(name.Value) &&
                                                    !string.IsNullOrWhiteSpace(nickName.Value)));

            SaveCommand.Subscribe(arg => SaveCommandHandler());

            SaveCommand.CanExecuteObservable.Subscribe(HandleSaveCanExecuteChangedHandler);

            DeleteCommand = ReactiveCommand.Create(this.WhenAny(x => x.PlayerDetails.Id,
                                                                id => id.Value != Guid.Empty));

            DeleteCommand.Subscribe(async arg => await DeleteCommandHandler());

            DeleteCommand.CanExecuteObservable.Subscribe(HandleDeleteCanExecuteChangedHandler);

            CreateNewCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.PlayerDetails.IsDirty)
                                                      .Select(x => !x).Skip(1));

            CreateNewCommand.Subscribe(arg => CreateCommandHandler());

            CreateNewCommand.CanExecuteObservable.Subscribe(HandleNewCanExecuteChangedHandler);

            ShowStatsCommand = ReactiveCommand.Create();

            ShowStatsCommand.Subscribe(arg =>
            {
                var newId = arg is Guid ? (Guid?)arg : null;

                if (newId.HasValue)
                {
                    ClickedPlayerId = newId.Value;
                }
            });

            ShowStatsCommand.CanExecuteObservable.Subscribe(HandleShowStatsCommandChangedHandler);

            PlayerSummaryCommand = ReactiveCommand.Create();

            PlayerSummaryCommand.Subscribe(ShowSummary);

            PlayerDetailCommand = ReactiveCommand.Create();

            PlayerDetailCommand.Subscribe(ShowDetail);
        }