Hi Guys,
GridTemplateColumn not working using Code, but works if I use XAML.
I get lot of missing rows for some reason. Below is my code. my model is same as the sample you guys provide online.
Thanks for the Help!!
var grid = new SfDataGrid();
var data = new OrderInfoRepository();
grid.AutoGenerateColumns = false;
var label1 = new Label()
{
TextColor = Color.Black,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};
var label2 = new Label(){
TextColor = Color.Black,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};
var cellGrid = new Grid(){
ColumnDefinitions = {
new ColumnDefinition{Width = GridLength.Auto},
new ColumnDefinition{Width = GridLength.Auto}
}
};
cellGrid.Children.Add(label1,0,0);
cellGrid.Children.Add(label2, 1, 0);
label1.SetBinding(Label.TextProperty, "CustomerID");
label2.SetBinding(Label.TextProperty, "ShipCountry");
var template = new GridTemplateColumn(){HeaderText = "Custom", MappingName = "OrderID" , Width = 250};
var dataTemplate = new DataTemplate(() =>
{
return cellGrid;
});
template.CellTemplate = dataTemplate;
grid.Columns.Add(template);
grid.ColumnSizer = ColumnSizer.Auto;
grid.ItemsSource = data.OrderInfoCollection;
Content = grid;Attachment:
TestSyncFusion_9a21f5af.zip