private static void OnCurrentPageChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { DataPager datapager = (DataPager)d; if (e.NewValue != null && datapager.Source != null && (int)e.NewValue != (int)e.OldValue) { int newIndex = datapager.GetNewCurrentPageIndex((int)e.NewValue); if (datapager.CurrentPage == newIndex) // we do not want that MoveToPage to be called several times, so we check the index before { datapager.Source.MoveToPage(((int)e.NewValue) - 1); // -1 because Source has an zero-based page index } if (datapager._buttonPanel != null) { datapager.RefreshControl(); } } }