[.CS]
double yPosition;
ExtendedScrollView ScrollView;
AndroidScrollView androidScrollView;
public MainPage()
{
InitializeComponent();
dataGrid.GridLoaded += DataGrid_GridLoaded;
}
private async void DataGrid_GridLoaded(object sender, GridLoadedEventArgs e)
{
var container =(VisualContainer) dataGrid.GetType().GetProperty("VisualContainer", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(dataGrid);
if (Device.RuntimePlatform == Device.Android)
{
androidScrollView = (AndroidScrollView)container.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == "AndroidScrollOwner").GetValue(container);
}
else
{
ScrollView = (ExtendedScrollView)container.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == "ScrollOwner").GetValue(container);
}
}
private void Button_Clicked(object sender, EventArgs e)
{
if (Device.RuntimePlatform == Device.Android)
{
yPosition = androidScrollView.ScrollY;
}
else
{
yPosition = ScrollView.ScrollY;
}
}
private async void Button_Clicked_1(object sender, EventArgs e)
{
if (Device.RuntimePlatform == Device.Android)
{
await (androidScrollView as ExtScrollViewer).ScrollToAsync(0, yPosition,false);
}
else
{
await (ScrollView as ScrollView).ScrollToAsync(0, yPosition,false);
}
} |