|
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); |