// Your own interface
public interface IPageInterface
{
void OnAppearing();
void OnDisappearing();
}
// Main Page
public partial class Page1 : ContentPage
{
SfDataGrid sfGrid;
ViewModel viewModel;
public Page1()
{
InitializeComponent();
sfGrid = new SfDataGrid();
viewModel = new ViewModel();
this.BindingContext = viewModel;
this.Content = sfGrid;
}
protected override void OnAppearing()
{
(BindingContext as IPageInterface)?.OnAppearing();
sfGrid.ItemsSource = viewModel.OrdersInfo;
}
protected override void OnDisappearing()
{
// codes
}
}
// ViewModel inherited from the interface you have defined
public class ViewModel : IPageInterface
{
public ViewModel()
{
}
public void OnAppearing()
{
// code related to ItemSource
}
public void OnDisappearing()
{
}
} |
//Constructor
public Page1()
{
InitializeComponent();
sfGrid = new SfDataGrid();
viewModel = new ViewModel();
this.BindingContext = viewModel;
sfGrid.ItemsSource = viewModel.OrdersInfo;
this.Content = sfGrid;
}
protected override void OnAppearing()
{
(BindingContext as IPageInterface)?.OnAppearing();
} |