Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Regarding point 1): Yes, use the ViewModel to bind against the UI rather than the DTO. This is the main idea to help separating the data from the view in MVVM.</p> <p>As for points 2) and 3) I suggest you to implement the <code>IEditableObject</code> interface on your ViewModels, possibly on a common base class.</p> <p>This Interface provides the methods <code>BeginEdit(), CancelEdit(), and EndEdit()</code>. Using these methods gives you a clean and readable control over when which object is modified and when to submit these changes e.g. to a service or a database.</p> <p>Also, implementing these methods this gives you a mechanism to handle those different data Versions like the mentioned "ViewValue" and "ServiceValue". You could create a local copy of the ServiceValue as a fall-back when method <code>BeginEdit()</code> is called and recall this local fall-back value if method <code>CancelEdit()</code> is called. If <code>EndEdit()</code> is called, this is the time to submit the values back to the service and after that succeeds store the current Value in that local temp Value as the new fall-back.</p> <p><strong>Edit to add answer for point 1)</strong></p> <p>I am not sure if this is a "best practice", but at least this is what we would in at work.</p> <p>We usually organize the ViewModels in such a way that we have one ViewModel per view that contains all information for a certain view. Let's call this the "main ViewModel". If we need a hierarchy of views, we would implement an hierarchy of ViewModels that follow the same hierarchy.</p> <p>In a case like yours we would put the DataGrid into another <code>UserControl</code> that is contained within the main View. The main ViewModel would hold another ViewModel that again holds the data needed for the DataGrid. This ViewModel would be set as the DataContext of that DataGrid-UserControl. This way you still preserve a clean one-ViewModel-per-View separation.</p> <p>Additional formatting of the data in the DataGrid might then be configured va <code>Templates</code>.</p>
 

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