Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>Chromosome</code> is your Model. Your XAML code resides in your View. The hypothetical "modified-length" value should reside in your ViewModel.</p> <p>You are correct in saying that making a new property for the modified height is not MVVM (and is a very bad idea generally, of course).</p> <p>For a better approach, you would normally put the modified-length property in the ViewModel. However your problem is now that your ViewModel has an <code>ObservableCollection&lt;Chromosome&gt;</code> and therefore cannot provide a simple modified-length property for each one of the <code>Chromosome</code> instances.</p> <p>Therefore, you have two choices:</p> <ol> <li><p>Implement a <a href="http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter.aspx" rel="nofollow"><code>ValueConverter</code></a> that translates the original <code>Length</code> to an appopriate <code>Grid.Height</code>. This could be either in your ViewModel or the View, but I think putting it in the ViewModel is not appropriate (since it will be used by a specific View only). This is the simplest approach.</p></li> <li><p>Wrap every <code>Chromosome</code> in its own ViewModel, e.g. <code>ChromosomeViewModel</code>. Your existing ViewModel would take a collection of <code>Chromosome</code>s and expose an <code>ObservableCollection&lt;ChromosomeViewModel&gt;</code>. You would then create a <code>ChromosomeView</code> bound to each ViewModel, which would basically be what you have now in your <code>ChromosomeDataTemplate</code>. Since the <code>ChromosomeView</code> will be bound to a <code>ChromosomeViewModel</code>, which in turn wraps a single <code>Chromosome</code>, you can now provide a "modified-length" property directly in your <code>ChromosomeViewModel</code>.</p></li> </ol> <p>If it's just for this, I suggest going with the <code>ValueConverter</code>. However, keep the second approach in mind for more complex scenarios.</p>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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