Note that there are some explanatory texts on larger screens.

plurals
  1. PODoes this MSDN article violate MVVM?
    primarykey
    data
    text
    <p>This may be old news but back in March 2009, this article, “<a href="http://msdn.microsoft.com/en-us/magazine/dd458800.aspx" rel="nofollow noreferrer">Model-View-ViewModel In Silverlight 2 Apps</a>,” has a code sample that includes <code>DataServiceEntityBase</code>:</p> <pre><code>// COPIED FROM SILVERLIGHTCONTRIB Project for simplicity /// &lt;summary&gt; /// Base class for DataService Data Contract classes to implement /// base functionality that is needed like INotifyPropertyChanged. /// Add the base class in the partial class to add the implementation. /// &lt;/summary&gt; public abstract class DataServiceEntityBase : INotifyPropertyChanged { /// &lt;summary&gt; /// The handler for the registrants of the interface's event /// &lt;/summary&gt; PropertyChangedEventHandler _propertyChangedHandler; /// &lt;summary&gt; /// Allow inheritors to fire the event more simply. /// &lt;/summary&gt; /// &lt;param name="propertyName"&gt;&lt;/param&gt; protected void FirePropertyChanged(string propertyName) { if (_propertyChangedHandler != null) { _propertyChangedHandler(this, new PropertyChangedEventArgs(propertyName)); } } #region INotifyPropertyChanged Members /// &lt;summary&gt; /// The interface used to notify changes on the entity. /// &lt;/summary&gt; event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged { add { _propertyChangedHandler += value; } remove { _propertyChangedHandler -= value; } } #endregion </code></pre> <p>What this class implies is that the developer <em>intends</em> to bind visuals <em>directly</em> to data (yes, a ViewModel is used but it defines an <code>ObservableCollection</code> of data objects). Is this design diverging too far from the guidance of MVVM? Now I can see some of the reasons Why would we go this way: what we can do with <code>DataServiceEntityBase</code> is this sort of thing (which is intimate with the Entity Framework):</p> <pre><code>// Partial Method to support the INotifyPropertyChanged interface public partial class Game : DataServiceEntityBase { #region Partial Method INotifyPropertyChanged Implementation // Override the Changed partial methods to implement the // INotifyPropertyChanged interface // This helps with the Model implementation to be a mostly // DataBound implementation partial void OnDeveloperChanged() { base.FirePropertyChanged("Developer"); } partial void OnGenreChanged() { base.FirePropertyChanged("Genre"); } partial void OnListPriceChanged() { base.FirePropertyChanged("ListPrice"); } partial void OnListPriceCurrencyChanged() { base.FirePropertyChanged("ListPriceCurrency"); } partial void OnPlayerInfoChanged() { base.FirePropertyChanged("PlayerInfo"); } partial void OnProductDescriptionChanged() { base.FirePropertyChanged("ProductDescription"); } partial void OnProductIDChanged() { base.FirePropertyChanged("ProductID"); } partial void OnProductImageUrlChanged() { base.FirePropertyChanged("ProductImageUrl"); } partial void OnProductNameChanged() { base.FirePropertyChanged("ProductName"); } partial void OnProductTypeIDChanged() { base.FirePropertyChanged("ProductTypeID"); } partial void OnPublisherChanged() { base.FirePropertyChanged("Publisher"); } partial void OnRatingChanged() { base.FirePropertyChanged("Rating"); } partial void OnRatingUrlChanged() { base.FirePropertyChanged("RatingUrl"); } partial void OnReleaseDateChanged() { base.FirePropertyChanged("ReleaseDate"); } partial void OnSystemNameChanged() { base.FirePropertyChanged("SystemName"); } #endregion } </code></pre> <p>Of course MSDN code can seen as “toy code” for educational purposes but is anyone doing anything like this in the <em>real</em> world of Silverlight development?</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.
 

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