I need to create a RadDataGrid where rows are dynamic custom control coming from API. I had asked a question before and it's helped me a lot. But currently, I cannot work more than one row. The first-row creation is very fine it's working so nicely with my custom controls, but not for the rest rows.
If I use Label it works, but not in a dynamic custom control.
private void AddHeaderRowNew(IEnumerable<string> headers)
{
Feature newTree = (this.Parent as Home).GetNewTree();
Dto.FeatureContainer container = Controls.ControlFactory.GetContainer(this.Template, newTree, this.Olp.AppProject.Layout.MetaTree,
FeatureState.New,
this.TreeRules,
ApiClient.Models.RuleTarget.Tree);
var views = container.GetViews(this.SimpleTreeElementIds);
int index = 0;
var columnWidth = Application.Current.MainPage.Width / headers.Count();
foreach (string header in headers)
{
var view = views[index];
columns.Add(header);
this.dataGrid.Columns.Add(new DataGridTemplateColumn { SizeMode = DataGridColumnSizeMode.Fixed, Width = columnWidth, HeaderText = header, Name = header, CanUserFilter = false, CanUserGroup = false, CanUserSort = false, CanUserEdit = true, HeaderStyle = new DataGridColumnHeaderStyle { BorderThickness = new Thickness(0) }, CellContentTemplate = GetTemplate(view) });
index++;
}
}
public DataTemplate GetTemplate(View view) //working only for first row
{
return new DataTemplate(() =>
{
var stackLayout = new StackLayout();
stackLayout.Children.Add(view);
return stackLayout;
});
}
public DataTemplate GetTemplate(string text) //working fine
{
return new DataTemplate(() =>
{
var stackLayout = new StackLayout();
Label oLabel = new Label()
{
BackgroundColor = Color.Transparent,
TextColor = Color.Black,
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
};
//oLabel.SetBinding(Label.TextProperty, psPropertyName);
oLabel.Text = text;
stackLayout.Children.Add(oLabel);
return stackLayout;
});
}
public IList<View> GetViews(IEnumerable<int> elementIds)
{
List<View> selected = new List<View>();
foreach (int i in elementIds)
{
selected.AddRange(this.Views.Where(x => (x as Controls.IF4View).ElementId == i));
}
return selected;
}