I have an XML file with several child elements. Each child element contains a series of elements, but the XML schema is undocumented, so I cannot possibly account for every possible element name. My goal is to provide an editor view for each child element. For example:
XML File
<root>
<element>
<subelement1>value</subelement>
<randomName88787>value</randomName>
<somethingTotallyFunky>value</somethingTotallyFunky>
<iHaveNoIdeaWhatThisWillBe>value</iHaveNoIdeaWhatThisWillBe>
</element>
</root>
I was hoping to use the WPF Toolkit's PropertyGrid control (or something similar) to present a list of all child elements of <element>
, but this control is designed to be bound to a CLR object. Of course I can't define a class with properties because I don't know what those properties will be. I've tried the following code to bind to an expando object:
var expando = new ExpandoObject();
var dict = (IDictionary<string, object>)expando;
foreach (var prop in unit.Elements())
{
if (dict.ContainsKey(prop.Name.LocalName) == false)
{
dict.Add(prop.Name.LocalName, (string)prop.Value);
}
}
Properties.SelectedObject = expando;
But no properties are displayed. It doesn't seem to handle ExpandoObject very well. Is there a better way to approach what I'm trying to do? A better control to do it with?