using Syncfusion.Maui.
DataGrid;
using Microsoft.Maui.Controls;
using System.Collections.ObjectModel;
namespace YourNamespace
{
public class YourPage : ContentPage
{
public YourPage()
{
try
{
// Sample data
var data = new ObservableCollection<YourDataModel>
{
new YourDataModel { Column1 = "Value1", Column2 = "Value2" },
new YourDataModel { Column1 = "Value3", Column2 = "Value4" }
};
// Create DataGrid
var dataGrid = new SfDataGrid
{
AutoGenerateColumns = false,
ItemsSource = data,
BackgroundColor = Color.White,
GridStyle = new MaterialGridStyle()
};
// Define columns
dataGrid.Columns.Add(new GridTextColumn
{
MappingName = "Column1",
HeaderText = "Header1",
CellStyle = new DataGridCellStyle { BackgroundColor =
Color.LightGray }
});
dataGrid.Columns.Add(new GridTextColumn
{
MappingName = "Column2",
HeaderText = "Header2",
CellStyle = new DataGridCellStyle { BackgroundColor =
Color.LightGray }
});
// Add DataGrid to layout
Content = new StackLayout
{
Children = { dataGrid },
Padding = new Thickness(20),
BackgroundColor = Color.LightBlue
};
}
catch (Exception ex)
{
// Error handling
DisplayAlert("Error", ex.Message, "OK");
}
}
}
public class YourDataModel
{
public string Column1 { get; set; }
public string Column2 { get; set; }
}
}