This repository was archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathListScrollTo.cs
99 lines (84 loc) · 2.34 KB
/
ListScrollTo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Xamarin.Forms.Controls
{
public class RandomSizeCell
: TextCell
{
static readonly Random Rand = new Random(42);
public RandomSizeCell()
{
SetBinding(TextProperty, new Binding("."));
Height = Rand.Next(25, 60);
}
}
public class ListScrollTo
: ContentPage
{
readonly List<List<string>> _items = new List<List<string>>();
bool _animate = true;
readonly ListView _listView;
public ListScrollTo()
{
Title = "ListView ScrollTo";
for (int i = 0; i < 10; i++)
{
List<string> subItems = new List<string>();
for (int x = 0; x < 10; x++)
{
subItems.Add(((i * 10) + x + 1).ToString());
}
_items.Add(subItems);
}
_listView = new ListView
{
Header = "Fooooo",
Footer = "Baaaaar",
ItemsSource = _items,
IsGroupingEnabled = true,
GroupDisplayBinding = new Binding("[0]"),
GroupShortNameBinding = new Binding("[0]"),
HasUnevenRows = true,
ItemTemplate = new DataTemplate(typeof(RandomSizeCell))
};
_listView.ScrollTo(_items[2][1], _items[2], ScrollToPosition.Center, true);
var visible = new Button { Text = "Visible" };
visible.Clicked += (sender, args) => _listView.ScrollTo(_items[4][4], _items[4], ScrollToPosition.MakeVisible, _animate);
var start = new Button { Text = "Start" };
start.Clicked += (sender, args) => _listView.ScrollTo(_items[4][4], _items[4], ScrollToPosition.Start, _animate);
var center = new Button { Text = "Center" };
center.Clicked += (sender, args) => _listView.ScrollTo(_items[4][4], _items[4], ScrollToPosition.Center, _animate);
var end = new Button { Text = "End" };
end.Clicked += (sender, args) => _listView.ScrollTo(_items[4][4], _items[4], ScrollToPosition.End, _animate);
var animate = new Button { Text = "Animate" };
animate.Clicked += (sender, args) =>
{
_animate = !_animate;
animate.Text = (_animate) ? "Animate" : "No Animate";
};
var buttons = new StackLayout
{
Orientation = StackOrientation.Horizontal,
Spacing = 1,
HorizontalOptions = LayoutOptions.Center,
Children = {
visible,
start,
center,
end,
animate
}
};
Content = new StackLayout
{
Children = {
buttons,
_listView
}
};
}
}
}