I'm comparatively fresh to C# and WPF, so forgive me for any lack of clarity in this question.
I developed my datamodel as a class library, such that it's not tied to a particular UI framework, or indeed any UI at all. There is good reason for this, as the library may be used to support multiple UI implementations.
Let's suppose it looks like this:
public class MyDataStore
{
public string Title { get; private set; }
public List<MyDataRecord> Records { get; private set; }
}
I then have a UI for viewing and manipulating this datamodel; let's suppose it's a WPF form with a DataGrid.
Now you can't bind to a List
, which is fine.
Were this entirely a UI project, I could simply change Records to be an ObservableCollection
, but this doesn't suit this library - aside from the principles of it, I update the list from a worker thread, and you can't push that operation onto a UI thread if you don't know about a UI.
The direct manual replacement is maintaining event subscription for every list item and cascading it up through the hierarchy - ick. Alternatively the UI has to adopt subscription on a per-item basis, which is a departure from the current state of it handling everything on a top-down basis.
I can think of a few designs that would work around this, but it must be a common problem: is there an appropriate design, pattern or framework to get the benefits and ease of binding, whilst maintaining distinct UI and model separation?