void ContentListView_SizeChanged(object sender, SizeChangedEventArgs e) { int index = (int)ContentListView.GetValue(ContentListViewChangeViewRequestProperty); if (index >= 0 && e.NewSize.Height > 10 && ContentListView.Items.Count > 0 && index < ContentListView.Items.Count) { ContentListView.UpdateLayout(); ContentListView.ScrollIntoView(ViewModel.Contents[index], ScrollIntoViewAlignment.Leading); index = -1; ContentListView.SizeChanged -= ContentListView_SizeChanged; } }
void ChangeView(int page, int line = -1) { if (line >= 0) { ContentListView.UpdateLayout(); if (ContentListView.Items.Count == 0) { ContentListView.SetValue(ContentListViewChangeViewRequestProperty, line); ContentListView.SizeChanged += ContentListView_SizeChanged; } else if (line < ContentListView.Items.Count) { ContentListView.ScrollIntoView(ViewModel.Contents[line], ScrollIntoViewAlignment.Leading); } } }