Previously i was Deserialize json to model class as below:
public class Product{
public string ProductName {get; set;}
public string ProductID {get; set;}
}
var result = await DeserializeJson<Ienumrable<Product>>(jsonString)
But now our objective is we do not want this model class anymore. This is because it is not a good way if later in future the web api is updated or got changes so the client side need to change as well in the model class. We do not want to rely on that anymore instead of make it to be auto generated.
We changed the deserialization to be as below:
*not use Product class model anymore.
var result = await DeserializeJson<dynamic>(jsonString)
In Viewmodel
the datasource is define as ObservableCollection for Xamdatagrid.
While trying to populate the datasource to the results above got error as because xamdatagrid cannot digest the Json string value.
I understand your point. AutoGenerateFields works when the bound data source is supported by XamDataGrid, but we are afraid to say that ExpandoObject is not supported by XampDataGrid. You can suggest new product ideas for future versions (or vote for existing ones) at <https://ko.infragistics.com/community/ideas>.
Submitting your idea will allow you to communicate directly with our product management team, track the progress of your idea at any time, see how many votes it got, read comments from other developers in the community, and see if someone from the product team has additional questions for you.
Please kindly understand that when you submit your idea, it will be greatly appreciated to explain the context in which a feature would be used. You can also link back to this thread for additional details.
Thank you in advance.
Understood on that, but what is the purpose of autogeneratefields? why it cannot autogeneratefields of dynamic object data?
<igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings HeaderPrefixAreaDisplayMode="FieldChooserButton" ExpansionIndicatorDisplayMode="CheckOnDisplay" HighlightAlternateRecords="True" AutoGenerateFields="True"/> </igDP:XamDataGrid.FieldLayoutSettings>
Hello,
You would use FieldLayoutInitialized event as you can see in those threads you mentioned. MVVM is a concept to separate Model, View and ViewModel. Therefore, writing a code behind a View to create view objects go together with MVVM as long as it doesn't include business logic.
Or you might also want to create a kind of wrapper which converts BindoObject into DataTable and bind the data table to XamDataGrid. This is also mentioned in the conversations you refer to. Here is a code sample. Please kindly understand that this code snippet is just for the purpose that you can get a grip on the basic concept. It assumes several things such as each item has every property, the properties are in the same order, and so on, which are not presupposed by Json. You might need to modify it by yourself if it is necessary.
public static DataTable ToDataTable(this IEnumerable<dynamic> items) { var data = items.ToArray(); if (data.Count() == 0) return null; var dt = new DataTable(); foreach(var key in ((IDictionary<string, object>)data[0]).Keys) { dt.Columns.Add(key); } foreach (var d in data) { dt.Rows.Add(((IDictionary<string, object>)d).Values.ToArray()); } return dt; }
Hi, i think something that i wanted to same as this link below:
(+) Dynamic Columns using ExpandoObject | Infragistics Forums
And
(+) Can I Bind an ExpandoObject to a xamDataGrid | Infragistics Forums
We wanted to populate list of dynamic object to xamdatagrid but seems xamdatagrid unable to generate columns.
Do you have any solution instead of using FiedlayoutInitialized event and unboundfield? Do latest infragistic version got the feature for xamdatagrid to do so instead of using the event initialized?
The problem of this FiedlayoutInitialized event is need to do at code behind and unfortunately our project is using MVVM.
You can go through the above links to understand more what actually my objective.
Sorry for having kept you waiting and thank you for the patience.
Unfortunately, all XamDataGrid's dataSource can accept is an object which implements IEnuerable interface. As you might already know, that's why XamDataGrid doesn't accept any Json serialized strings.https://ko.infragistics.com/help/wpf/xamdatagrid-accessing-datahttps://ko.infragistics.com/help/wpf/infragisticswpf.datapresenter~infragistics.windows.datapresenter.datapresenterbase~datasource
So, no matter what reason you may have, you would need to have an IEnumerable object of a certain class in order to bind it to XamDataGrid. You would create a class dynamically and bind its enumerable collection to a XamDataGrid.
If your question is about how to create a class dynamically, we are afraid to say that it is beyond the scope of our developer support service because it is a question genuinely about C#, which is a Microsoft's product, not ours. Sorry again for not being able to be of your help, but please kindly understand that.
This just for your reference.You might want to see Microsoft public documents "MSDN" to check what can be done with System.Reflection.Emit namespace: https://docs.microsoft.com/en-us/dotnet/api/system.reflection.emit?view=netframework-4.8Or google it with keywords such as "class reflection dynamic c#".
If you have any question about binding to XamDataGrid itself AFTER you successfully create an enumerable object of a dynamically created class, please let us know.