Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF: Best way to create bindings to unknown types in MVVM
    primarykey
    data
    text
    <p>I am looking for a way to display data in a <code>DataGrid</code> from types that are unknown at compile-time.</p> <p>I have the following base class</p> <pre><code>public abstract class Entity { // Some implementation of methods ... } </code></pre> <p>In run-time, I load a plug-in DLL and use reflection to get a list of all the types derived from <code>Entity</code>. For example:</p> <pre><code>public class A : Entity { public LocalAddress Address{ get; set; } } public class B : Entity { public Vendor Vendor { get; set; } public string Name { get; set; } } </code></pre> <p>Then I retreive a list of their instances from DB</p> <pre><code>public IEnumerable&lt;Entity&gt; Entities { get; set; } // A list of instances of type A for example </code></pre> <p><code>Entities</code> is the DataGrid's <code>ItemsSource</code>, But what's the best way I can bind the properties to the <code>DataGrid</code>? Since the properties can be complex, I also need to be able to bind to a specific path, for example <code>Address.HomeNum</code> ...</p> <h2>Clarifications</h2> <ol> <li><p>I only need to show a one grid of a type's instances at a time. The complete scenario is this:</p> <ol> <li>I get a list of types that derive from <code>Entity</code> from the plug-in DLL through reflection</li> <li>I show their names in a List. (in this example that list will contain <code>A</code> and <code>B</code></li> <li>When the user clicks on a specific item, let's say <code>A</code>, I get a list of <code>A</code> instances from DB - so far so good.</li> <li>I want to display <strong>that list of <code>A</code>'s instances</strong> in a <code>DataGrid</code>.</li> <li>When the user selects another item from the list (meaning another type, lets say <code>B</code>), I get a list of <code>B</code>'s instances from DB and need to display those in the grid and so on ... </li> </ol></li> <li><p>The plug-in DLL is a class library with no xamls (also my users are the ones making this plug-ins and I don't want them to have to write <code>DataTemplate</code>s for their entities. I also can't make predifned <code>DataTemplate</code>s as I don't know the types I'll need to display until run-time. Each type can have different types and amount of properties. All I know in complie-time is that they all derived from <code>Entity</code>.</p></li> <li>The grid should also be editable.</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload