How do I dynamically generate columns in a WPF DataGrid?

Ultimately I needed to do two things: Generate the columns manually from the list of properties returned by the query Set up a DataBinding object After that the built-in data binding kicked in and worked fine and didn’t seem to have any issue getting the property values out of the ExpandoObject. <DataGrid AutoGenerateColumns=”False” ItemsSource=”{Binding Results}” … Read more

Why can’t I index into an ExpandoObject?

how the Expando was able to hide the method of one of its interfaces. Because as you correctly found out in the documentation, the indexer is an explicit interface implementation. From Explicit Interface Implementation Tutorial: A class that implements an interface can explicitly implement a member of that interface. When a member is explicitly implemented, … Read more

Binding a GridView to a Dynamic or ExpandoObject object

Since you can’t bind to an ExpandoObject, you can convert the data into a DataTable. This extension method will do that for you. I might submit this for inclusion to Massive. /// <summary> /// Extension method to convert dynamic data to a DataTable. Useful for databinding. /// </summary> /// <param name=”items”></param> /// <returns>A DataTable with … Read more

How to flatten an ExpandoObject returned via JsonResult in asp.net mvc?

Using JSON.NET you can call SerializeObject to “flatten” the expando object: dynamic expando = new ExpandoObject(); expando.name = “John Smith”; expando.age = 30; var json = JsonConvert.SerializeObject(expando); Will output: {“name”:”John Smith”,”age”:30} In the context of an ASP.NET MVC Controller, the result can be returned using the Content-method: public class JsonController : Controller { public ActionResult … Read more

How to detect if a property exists on an ExpandoObject?

According to MSDN the declaration shows it is implementing IDictionary: public sealed class ExpandoObject : IDynamicMetaObjectProvider, IDictionary<string, Object>, ICollection<KeyValuePair<string, Object>>, IEnumerable<KeyValuePair<string, Object>>, IEnumerable, INotifyPropertyChanged You can use this to see if a member is defined: var expandoObject = …; if(((IDictionary<String, object>)expandoObject).ContainsKey(“SomeMember”)) { // expandoObject.SomeMember exists. }