|
int index = 0;
public MainPage()
{
InitializeComponent();
GridTextColumn textColumn = new GridTextColumn();
textColumn.MappingName = "OrderID";
//// Changing header text when creating column manually.
textColumn.HeaderText = "Order ID" + " " + index.ToString();
dataGrid.Columns.Add(textColumn);
dataGrid.AutoGeneratingColumn += dataGrid_AutoGeneratingColumn;
index++;
}
private void dataGrid_AutoGeneratingColumn(object sender, AutoGeneratingColumnEventArgs e)
{
//// Changing header text when columns are auto generated.
e.Column.HeaderText = e.Column.MappingName + " " + index.ToString();
index++;
} |
|
GridNumericColumn firstColumn = new GridNumericColumn();
firstColumn.SetBinding(GridNumericColumn.HeaderTextProperty, new Binding("FirstColumnName", source: this.viewModel));
firstColumn.MappingName = "OrderID";
firstColumn.HeaderTemplate = new DataTemplate(() =>
{
var label = new Label();
label.HorizontalTextAlignment = TextAlignment.Center;
label.HorizontalOptions = LayoutOptions.Center;
label.VerticalTextAlignment = TextAlignment.Center;
label.SetBinding(Label.TextProperty, new Binding("FirstColumnName", source: this.viewModel));
return label;
});
GridTextColumn secondColumn = new GridTextColumn();
secondColumn.MappingName = "CustomerID";
secondColumn.HeaderTemplate = new DataTemplate(() =>
{
var label = new Label();
label.HorizontalTextAlignment = TextAlignment.Center;
label.HorizontalOptions = LayoutOptions.Center;
label.VerticalTextAlignment = TextAlignment.Center;
label.SetBinding(Label.TextProperty, new Binding("SecondColumnName", source: this.viewModel));
return label;
});
dataGrid.Columns.Add(firstColumn);
dataGrid.Columns.Add(secondColumn); |