Hello,
I need to display an array with a random amount of headers and lines.
I can have 2 to 20 columns and 10 to 200 lines.
So I need to be able to bind a list of headers and lines, all objects are in strings.
I already have another xamDatagrid with custom xaml style, so I would like to re-use it.
Thnaks for your help.
Regards
Thank you for your post.
I have been looking into it, but it seems like I am missing something about your scenario, so if this is still an issue for you, could you please send me, an isolated sample project, where this is reproduced, so I can investigate it further for you.
Looking forward to hearing from you.
The context of my project is :
I have two IEnumerables with string :
IEnumerable<string> Lines { get; } IEnumerable<string> Headers { get; }
In Headers, I have : "","Header1","Header2"
In Lines, I have : "10","Value1",Value2" // "15","Value3","Value4"
I want to display the grid with Headers as heards and Lines as rows with values.
To bind Headers only for columns title, and Lines for the content.
I can't give you a little solution.
Thank you for your feedback.
I am very glad that you have managed to resolve your issue. Please let me know if you need any further assistance on the matter.
I manage to do a 1 to 1 binding.
In my object I have two properties, it's possible to setup two fields for each one.
Now I have a list of objects. I want to display enough columns for each objects.
I can have 10 to 100 items, I want to display all items.
I work with MVVM, so maybe some code-behind will help me to do what I want ?
I make a lot of progress with this article : http://es.infragistics.com/community/blogs/blagunas/archive/2012/10/24/xamdatagrid-dynamically-create-and-data-bind-columns-with-an-editor-of-your-choice.aspx
So I have classes like :
public class IntensityLineDetails => that contains the value { public string Title { get; set; } public int Angle { get; set; }
public IntensityLineDetails(string title,int value) { Title = title; Angle = value; } }
public class IntensityLineViewModel => a list of values for one point { public double Azimuth { get; set; } public IList<IntensityLineDetails> Elevations { get; set; }
}
In my helper, I build fake lines with this :
yield return new IntensityLineViewModel { Azimuth = 1.0, Elevations = new List<IntensityLineDetails> { new IntensityLineDetails("10",6), new IntensityLineDetails("20",7), new IntensityLineDetails("30",15) } };
In my ViewModel :
public IEnumerable<IntensityLineViewModel> Lines { get { return lines; } set { Set(() => Lines, ref lines, value); } }
In my code behind :
private void xamDataGrid_FieldLayoutInitialized(object sender, Infragistics.Windows.DataPresenter.Events.FieldLayoutInitializedEventArgs e) { //a cheat to get the number of columns to create. var lines = this.ViewModel.Lines.First();
for (Int32 i = 0; i < lines.Elevations.Count; i++) { var field = new UnboundField { Name = lines.Elevations[i].Title, BindingMode = BindingMode.TwoWay };
field.AllowEdit = false; field.Settings.EditAsType = typeof(Int32);
e.FieldLayout.Fields.Add(field); } }
The result : http://gyazo.com/1c9851d49c46ab1a8b26d0a7ac01a71c
How to display the values from IntensityLineDetails ?
Thanks for your help
Now I use a field like this :
void xamDataGrid_FieldLayoutInitialized(object sender, FieldLayoutInitializedEventArgs e) { //a cheat to get the number of columns to create. var lines = this.ViewModel.Lines.First();
for (Int32 i = 0; i < lines.Values.Count; i++) { var field = new Field { Name = lines.Values[i].Title };
field.AllowEdit = false;
Values are missing and I have empty cells everywhere.
I need it before I release this update to my users.
Thank you for posting!
I have been looking into it.
It will be great if you could share a sample project that illustrates the behavior. This way I would be able to further investigate this for you and provide you with more detailed information on this matter. To upload an archive file you can choose the Options tab when you respond to a thread and click the Add/Update button. You can also create a support ticket (or I could create one on your behalf if you prefer) so that you can upload the sample and it is not public for the community.
I am just checking if there is anything else I can do for you.
I have been looking into it and I am not sure that understand what you are trying to achieve correctly. Would you please provide me with more details about what you want to style, it will be great if you could share sample project that illustrate the issue, so I will be able to further investigate it for you.
After some tests, I keep your solution with NumericEditor.
Now, I play with xaml lines and style setter.
I saw that you have a <Trigger Property="IsInEditMode" Value="True"> in XamMaskedEditor, if I want to style it when EditMode = false to have foreground with black color, how to code it ?
The list of period is dynamic so I can't hard code it.
I don't use UnboundField because it's too old for resharper/codeMaid so I use a field.
I try to get the previous field (that is fixed) and change the title but I have an exception.
Maybe the solution is to set the style as a cellValuePresenter or as a label.
All cells are empty and I know that the collection is good.
Hello ,
I have been looking into the sample application that you have provided and I am not sure how exactly you want to display your inner collection(Periods). It seems that the issue that you have described is caused by your view model. You can display your data in hierarchical grid, please see the attached image. In order to be able to achieve this, you just have to set AutoGenerateFields property of XamDataGrid to true.
If you want you can use UnboundField or you can set BindingType property of Field to Unbound. In CellValuePresenterStyle of this field you can create style for CellValuePresenter and set its Template property. In in it you can create ControlTemplate with TextBlock and by using MultiBinding you can set the DataContext of TextBlock to the current item of Periods collection. I modified you sample application in order to be able to show you how you can implement this approach.
Please let me know if you need any further assistance on the matter.