Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to deal with multiple views that share a lot of functionality?
    primarykey
    data
    text
    <p>I have a project that has three models: one base model, and two models that derive from the first.</p> <p>There are "editor" views for the derived models so the user can create/edit/delete. My problem is that these models share a lot of functionality (obviously). There are controls that would ideally be pulled out and put into their own views for each editor view to consume. My problem is that I also have a lot of drag and drop functionality going on where the user can drag an item out of a list from the base model, and drop it into a list on the derived model. </p> <p>I was going to pull out the shared controls and create editor views for the derived models, and also create views/viewmodels for the shared controls that the editor views consume using ContentControl (or something similar). Unfortunately I forgot about the drag-and-drop and I can't seem to drag from the shared control view to the editor view.</p> <p>Is there a solution to this, other than completely annihilating DRY?</p> <p>An example of how the code would look is this:</p> <p><strong>Models</strong>:</p> <pre><code>public class BaseModel { string Name; int Id; } public class DerivedModelOne { string SomeProperty; IEnumerable&lt;string&gt; ListOfSomeKind; } public class DerivedModelTwo { int AnInteger; } </code></pre> <p><strong>ViewModels:</strong></p> <pre><code>public class BaseEditorViewModel { public BaseModel; // And other such required properties } public class DerivedOneEditorViewModel { public BaseEditorViewModel; // And all the other properties for this model... } public class DerivedTwoEditorViewModel { public BaseEditorViewModel // And all the other properties... } </code></pre> <p><strong>And then the views for the derived editor views would be:</strong></p> <pre><code>&lt;UserControl&gt; &lt;Grid&gt; &lt;ContentControl FOR THE BASE /&gt; &lt;Label /&gt; &lt;TextBlock /&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p>I am also using <code>INotifyDataErrorInfo</code> but so far only on the derived view models. And in order for this to work (I think) I had to create properties on the derived view models for the base model properties (Name and Id) that get and set the corresponding properties on the base view model. Seems very dirty to me!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    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