|
//MainPage.xaml
<ContentPage.BindingContext>
<local:ViewModel x:Name="viewModel" />
</ContentPage.BindingContext>
<ContentPage.Content>
<sfgrid:SfDataGrid x:Name="sfGrid"
AutoGenerateColumns="False"
ItemsSource="{Binding OrdersInfo}"
AllowPullToRefresh="True"
PullToRefreshCommand ="{Binding Refresh}"
IsBusy="{Binding Busy}"
>
<sfgrid:SfDataGrid.Columns>
<sfgrid:GridTextColumn MappingName="OrderID" />
<sfgrid:GridTextColumn MappingName="EmployeeID" />
<sfgrid:GridTextColumn MappingName="CustomerID" />
<sfgrid:GridTextColumn MappingName="ShipCountry" HeaderText="Country"/>
</sfgrid:SfDataGrid.Columns>
</sfgrid:SfDataGrid>
</ContentPage.Content>
public class ViewModel : NotificationObject
{
public Command Refresh { get; set; }
private bool busy;
public bool Busy
{
get
{
return busy;
}
set
{
busy = value;
RaisePropertyChanged("Busy");
}
}
public ViewModel()
{
order = new OrderInfoRepository();
random = new Random();
Refresh = new Command(RefreshItems);
SetRowstoGenerate(50);
}
private async void RefreshItems()
{
this.Busy = true;
await Task.Delay(new TimeSpan(0, 0, 5));
ItemsSourceRefresh();
this.Busy = false;
}
public void ItemsSourceRefresh()
{
int count = random.Next(1, 6);
for (int i = 11000; i < 11000 + count; i++)
{
int value = i + random.Next(100, 150);
this.OrdersInfo.Insert(0, order.GenerateOrder(value));
}
}
} |