private void OnSelectedPageChanged() { try { var index = Configuration.Pages.IndexOf(SelectedPage); for (int i = 0; i < index; i++) { var page = Configuration.Pages.ElementAt(i); if (!page.Validate()) { Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new Action(() => SelectedPage = page)); return; } } IsLastPage = index == Configuration.Pages.Count - 1; } finally { NextPageCommand.RaiseCanExecuteChanged(); PrevPageCommand.RaiseCanExecuteChanged(); } }
public GameScreenSelectViewModel(List <Rectangle> rectList, SelectGameWindowAction dg) { this.rectList = rectList; this.dg = dg; // プロパティを設定 PageInfoStr = RectIndex.Select(x => $"[{x + 1}/{rectList.Count}] {Utility.GetRectStr(rectList[x])}").ToReadOnlyReactiveProperty(); GameWindowPage = RectIndex.Select(x => (BitmapSource)ScreenShotProvider.GetScreenBitmap(rectList[x]).ToImageSource()).ToReadOnlyReactiveProperty(); // コマンドを設定 PrevPageCommand.Subscribe(_ => { RectIndex.Value = (rectList.Count + RectIndex.Value - 1) % rectList.Count; }); NextPageCommand.Subscribe(_ => { RectIndex.Value = (rectList.Count + RectIndex.Value + 1) % rectList.Count; }); SelectPageCommand.Subscribe(_ => { dg(rectList[RectIndex.Value]); CloseWindow.Value = true; }); CancelCommand.Subscribe(_ => { dg(null); CloseWindow.Value = true; }); }
private void OnPropertyChanged(object sender, PropertyChangedEventArgs e) { NextPageCommand.RaiseCanExecuteChanged(); PrevPageCommand.RaiseCanExecuteChanged(); ButtonNext.Visibility = NextPageCommand.CanExecute(null) ? Visibility.Visible : Visibility.Hidden; ButtonPrev.Visibility = PrevPageCommand.CanExecute(null) ? Visibility.Visible : Visibility.Hidden; LabelPage.Content = PageCount == 1 ? null : $"{Page + 1}/{PageCount}"; if (ItemsSource == null) { return; } var pageSize = PageSize; PagedItemSource = new ObservableCollection <object>( ItemsSource.OfType <object>().Skip(Page * pageSize).Take(pageSize).ToList()); if (e.PropertyName == nameof(ItemsSource)) { Page = 0; } }
public Page2ViewModel(INavigationService navigationService) { PrevPageCommand.Subscribe(async _ => await navigationService.GoBackAsync()); FirstPageCommand.Subscribe(async _ => await navigationService.GoBackToRootAsync()); }