Search code examples
c#wpftreeview

WPF UI Design Question: How to represent data in a structured way from a single complex object


WPF noob here...

I would like some advice around how I could present data to a user in a structured, easy to understand way. My data is coming from a large JSON string that gets parsed into a single object that is reasonably complex. The object consists largely of a variety of individual strings and arrays that is structured in a fairly hierarchical pattern.

Here is a flavour of what I'm working with (note the nested []s keeps going on for a few more layers):

public class MyBigFatModel
{
    [JsonProperty("blah")]
    public Blah blah { get; set; }

    [JsonProperty("codeythingy")]
    public string Codeythingy { get; set; }

    public partial class Blah
    {
        [JsonProperty("uuid")]
        public string Uuid { get; set; }

        [JsonProperty("created")]
        public DateTime Created { get; set; }

        [JsonProperty("modified")]
        public object Modified { get; set; }

        [JsonProperty("info")]
        public Info Info { get; set; }

        [JsonProperty("thingyTemplates")]
        public ThingyTemplate[] ThingyTemplates { get; set; }

        [JsonProperty("thingy")]
        public Thingy Thingy { get; set; }
    }

    public partial class Thingy
    {
        [JsonProperty("type")]
        public string Type { get; set; }

        [JsonProperty("thingyblah")]
        public ThingyBlah ThingyBlah { get; set; }

        [JsonProperty("oudgit")]
        public Oudgit Oudgit { get; set; }

        [JsonProperty("customer")]
        public string Customer { get; set; }
        
        [JsonProperty("location")]
        public string Location { get; set; }

        [JsonProperty("comment")]
        public string Comment { get; set; }
    }

    public partial class ThingyBlah
    {
        [JsonProperty("NameDesc1")]
        public string NameDesc1 { get; set; }
                    
        [JsonProperty("NameDesc2")]
        [JsonConverter(typeof(ParseStringConverter))]
        public long BNameDesc2 { get; set; }

        ...

        [JsonProperty("serialNo")]
        public string SerialNo { get; set; }

        [JsonProperty("version")]
        public string Version { get; set; }

        [JsonProperty("something")]
        public long Something { get; set; }

        [JsonProperty("fileUUID")]
        public string FileUuid { get; set; }

        [JsonProperty("pcUUID")]
        public string PcUuid { get; set; }
    }

    public partial class Oudgit
    {
        
        [JsonProperty("version")]
        public string Version { get; set; }

        [JsonProperty("battLevel")]
        public long BattLevel { get; set; }

        [JsonProperty("state")]
        public string State { get; set; }

        [JsonProperty("timestamp")]
        public DateTime Timestamp { get; set; }       
        

        [JsonProperty("wotsies")]
        public Wotsies[] Wotsies { get; set; }

        [JsonProperty("somethinorother")]
        public Somethinorother[] Somethinorothers { get; set; }

        
    }

You get the picture

Initially I wanted to use a TreeView but as far as I can see it only binds to a collection not an individual object.

Any suggestions around how I might represent this data in a hierarchical fashion that will allow a user to drill into the data?

I'm still open to using Treeview but my limited understanding would lead me to think that I'd need to pull the object apart and create a bunch of new collections I can point the tree to.

Any ideas, advice etc would be greatly appreciated!


Solution

  • For posterity: I ended up using a Treeview. Worked nicely for quite a few layers but I had an array at the bottom level of the JSON object. It just wouldn't display the array elements. I ended up having to mess with my bindings to get it to work. Didn't have to to this for any of the arrays higher up in the hierarchy. Weird but it still worked. Thanks for the collective wisdom folks!