<sfgrid:GridColumn.HeaderTemplate> and adding data template to it. Could you tell, how this can be done programatically while adding a column dynamically?|
GridTextColumn OrderIDColumn = new GridTextColumn()
{
MappingName = "OrderID",
HeaderTemplate = new DataTemplate(() =>
{
Label orderIDLabel = new Label();
orderIDLabel.Text = "Order ID";
orderIDLabel.BackgroundColor = Color.LightBlue;
orderIDLabel.TextColor = Color.White;
return orderIDLabel;
})
};
GridTextColumn CustomerIDColumn = new GridTextColumn()
{
MappingName = "CustomerID",
HeaderTemplate = new DataTemplate(() =>
{
Label customerIDLabel = new Label();
customerIDLabel.Text = "Customer ID";
customerIDLabel.BackgroundColor = Color.LightBlue;
customerIDLabel.TextColor = Color.White;
return customerIDLabel;
})
};
…………
…………
…………
…………
dataGrid.Columns.Add(OrderIDColumn);
dataGrid.Columns.Add(CustomerIDColumn);
dataGrid.Columns.Add(firstNameColumn);
dataGrid.Columns.Add(lastNameColumn);
dataGrid.Columns.Add(shipCityColumn);
|
|
public class MainActivity : Activity
{
SfDataGrid dataGrid;
protected override void OnCreate(Bundle bundle)
{
dataGrid = new SfDataGrid(BaseContext);
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
OrderInfoRepository viewModel = new OrderInfoRepository();
dataGrid.ItemsSource = viewModel.OrderInfoCollection;
dataGrid.AutoGenerateColumns = false;
dataGrid.ColumnSizer = ColumnSizer.Star;
dataGrid.AllowDraggingRow = true;
TextView OrderIDTextView = new TextView(this);
OrderIDTextView.Text = "Order ID";
OrderIDTextView.SetBackgroundColor(Color.LightBlue);
OrderIDTextView.SetTextColor(Color.White);
GridTextColumn OrderIDColumn = new GridTextColumn();
OrderIDColumn.HeaderTemplate = OrderIDTextView;
OrderIDColumn.MappingName = "OrderID";
OrderIDColumn.LoadUIView = true;
TextView CustomerIDTextView = new TextView(this);
CustomerIDTextView.Text = "Customer ID";
CustomerIDTextView.SetBackgroundColor(Color.LightBlue);
CustomerIDTextView.SetTextColor(Color.White);
GridTextColumn CustomerIDColumn = new GridTextColumn();
CustomerIDColumn.HeaderTemplate = CustomerIDTextView;
CustomerIDColumn.MappingName = "CustomerID";
CustomerIDColumn.LoadUIView = true;
…
…
dataGrid.Columns.Add(CustomerIDColumn);
dataGrid.Columns.Add(OrderIDColumn);
dataGrid.Columns.Add(ShipCountryColumn);
dataGrid.Columns.Add(CustomerColumn);
dataGrid.Columns.Add(ShipCityColumn);
LinearLayout linear = FindViewById<LinearLayout>(Resource.Id.linear);
linear.AddView(dataGrid);
}
}
|