title: WPF: Databinding to properties named at runtime
body: <p>I am working on a project for modifying a specific sort of binary file format. Part of the specification is to allow XML definitions of struct layouts, like so:</p>
  
  <pre><code>&lt;!-- Invalid plugin, for demonstration only --&gt;
  &lt;plugin name="weap"&gt;
      &lt;struct size="0x504"&gt;
          &lt;float32 name="initial_rounds_per_second" offset="0x4" /&gt;
          &lt;float32 name="final_rounds_per_second" offset="0x8" /&gt;
          &lt;float32 name="rounds_per_second_acceleration" offset="0xA" /&gt;
          &lt;float32 name="rounds_per_second_deceleration" offset="0xC" /&gt;
          &lt;uint16 name="projectiles_per_shot" offset="0x6E" /&gt;
          &lt;array name="magazines" offset="0xF0"&gt;
              &lt;struct size='112'&gt;
                  &lt;uint16 name="rounds_recharged" offset="0x4" /&gt;
                  &lt;uint16 name="rounds_total_initial" offset="0x6" /&gt;
                  &lt;uint16 name="rounds_total_maximum" offset="0x8" /&gt;
                  &lt;uint16 name="rounds_loaded_maximum" offset="0xA" /&gt;
              &lt;/struct&gt;
          &lt;/array&gt;
      &lt;/struct&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>These XML plugins are loaded at runtime and used to interpret the binary file. I have a working prototype in Python which, at runtime, interprets these plugins and generates classes based on them.</p>
  
  <p>My trouble is with WPF databinding -- WPF needs to know the names of the properties it will bind to at compile-time. I would like to databind the WPF GUI to these plugin-defined data structures, so I'm in a bit of a pickle.</p>
  
  <p><strong>How can I databind to properties whose names I don't know until runtime?</strong></p>
  
  <p>The only tentative solution I've been able to think of is storing all of this information in a "Fields" property of type <code>Dictionary&lt;String,Object&gt;</code>, where the string => object mapping represents the named elements. WPF can then bind to this Dictionary, using data templates to list out each key/value pair.</p>
  
  <p>However, my inexperience with WPF puts me on shaky ground, and my solution raises a number of other questions:</p>
  
  <ul>
  <li>Is this Dictionary approach a good way to solve the problem?</li>
  <li>Which observable datatype ought I to use?</li>
  <li>If one value in the dictionary is updated, does WPF need to refresh the whole collection?</li>
  <li>Will I have performance issues if the dictionary consists of hundreds of key/value pairs?</li>
  </ul>