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(); } }
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; } }