public XamarinListViewScrollToBugPage1() { Title = "Scroll To in OnAppearing"; for (int i = 0; i < 100; i++) { var item = new ListObj { Name = string.Format("{0} {0} {0} {0} {0} {0}", i) }; _collection.Add(item); } _listView = new ListView { ItemsSource = _collection, ItemTemplate = new DataTemplate(typeof(CellTemplateScrollTo)) }; _listView.AutomationId = "listView"; Content = new StackLayout { Children = { _listView } }; }
void BtnAddOnClicked(object sender, EventArgs eventArgs) { var str = string.Format("Item {0}", _i++); var item = new ListObj { Name = string.Format("{0} {0} {0} {0} {0} {0}", _i) }; _collection.Add(item); _listView.ScrollTo(item, ScrollToPosition.End, true); }
public XamarinListViewScrollToBugPage2() { Padding = new Thickness(10, 50, 10, 0); Title = "Crash in ScrollToPosition.End"; for (int i = 0; i < 100; i++) { var item = new ListObj { Name = string.Format("2 {0} {0} {0} {0} {0} {0}", i) }; _collection.Add(item); } _listView = new ListView { ItemsSource = _collection, ItemTemplate = new DataTemplate(typeof(CellTemplateScrollTo)) }; var endButton = new Button { Text = "ScrollToPosition.End End - Not animated", Command = new Command(() => { _listView.ScrollTo(_collection.Last(), ScrollToPosition.End, false); }) }; var endButtonAnimated = new Button { Text = "ScrollToPosition.MakeVisible End - Animated", Command = new Command(() => { _listView.ScrollTo(_collection.Last(), ScrollToPosition.MakeVisible, true); }) }; Content = new StackLayout { Children = { endButton, endButtonAnimated, _listView } }; }
public XamarinListViewScrollToBugPage3() { Title = "Scroll To in OnAppearing Uneven"; bool runTest = true; // This test will fail in iOS < 9 because using ScrollTo with UnevenRows with estimation is currently not working. // It did not previously fail because this test used `TakePerformanceHit` to turn off row estimation. However, as // that was never a public feature, it was never a valid fix for the test. // https://bugzilla.xamarin.com/show_bug.cgi?id=28277 #if !UITEST if (App.IOSVersion < 9) { runTest = false; } #endif if (!runTest) { _collection.Add(new ListObj { Name = DontRun }); } else { for (_i = 0; _i < 100; _i++) { var item = new ListObj { Name = string.Format("{0} {0} {0} {0} {0} {0}", _i) }; _collection.Add(item); } } var btnAdd = new Button { Text = "Add item", WidthRequest = 100 }; btnAdd.Clicked += BtnAddOnClicked; var btnBottom = new Button { Text = "Scroll to end", WidthRequest = 100 }; btnBottom.Clicked += BtnBottomOnClicked; var btnPanel = new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.Center, Children = { btnAdd, btnBottom } }; _listView = new ListView { ItemsSource = _collection, BackgroundColor = Color.Transparent, VerticalOptions = LayoutOptions.FillAndExpand, HasUnevenRows = true, ItemTemplate = new DataTemplate(typeof(CellTemplateScrollToUneven)) }; _listView.ItemTapped += (sender, e) => ((ListView)sender).SelectedItem = null; _listView.AutomationId = "listView"; Content = new StackLayout { Children = { btnPanel, _listView } }; }