SilverlightShow: ModalDialogs, IEditableObject and MVVM in Silverlight 4 Comments http://www.silverlightshow.net/ Silverlight articles, Silverlight tutorials, Silverlight videos, Silverlight samples SilverlightShow.net http://www.rssboard.org/rss-specification Argotic Syndication Framework 2008.0.2.0, http://www.codeplex.com/Argotic en-US estoychev@completit.com (Emil Stoychev) Re: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Maybe you don't need to:</p> <p>Another approach is to break this problem down into more manageable pieces:</p> <p>- A CompanyList VM and V for the company list<br /> - A Company VM and V for handing the Company properties and the list of EditableEmployees (Employee wrapped in generic IEditableObject)<br /> - A Employee VM and V for handling the Employee properties</p> <p>The CompanyViewModel could have commands to add/remove/edit employees and these would create a EmployeeViewModel (and calling BeginEdit on the Employee in case of edit) and use that as datacontext of an EmployeeView shown in a model dialog, and handle the result of the modal dialog (calling CancelEdit on cancel, or EndEdit on OK)...<br /> <br /> </p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment7283 geertd http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Sun, 04 Dec 2011 15:40:09 GMT Re: ModalDialogs, IEditableObject and MVVM in Silverlight 4 Hi geertd, you are right, the IEditableObject implemenation will not work in that scenario. It will require additional work to handle hierarchies. http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment7282 ppopadiyn http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Sun, 04 Dec 2011 15:22:00 GMT Re: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Suppose that you are working with a hierarchical structure e.g. a Company class that has a list of Persons. You select a Company from a list, open up a modal dialog to edit that company and start editing it: change the Company.Name, change the name of the first person of that company, add a new person... and then you want to cancel.</p> <p>I don't think the generic implementation of IEditableObject handles such a hierarchy?</p> <p>How would you handle such a case?</p> <p><br /> </p> <p><br /> </p> <p><br /> </p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment7279 geertd http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Sun, 04 Dec 2011 13:16:19 GMT Re: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>clean work! excellent! could this be applied also for WPF and I mainly worked with DI frameworks (autofac) is there any particular reason you preffered MEF over DI Framerwork? as far as I know MEF's primary role is not about DI.</p> <p>thanks </p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment6296 mobygeek http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Thu, 16 Jun 2011 14:06:03 GMT Re: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p><span style="font-family: arial, sans-serif; font-size: 16px;"><span class="hps" title="Clique para mostrar traduções alternativas">Thanks</span><span title="Clique para mostrar traduções alternativas">,</span> <span class="hps" title="Clique para mostrar traduções alternativas">your article</span> <span class="hps" title="Clique para mostrar traduções alternativas">is</span> <span class="hps" title="Clique para mostrar traduções alternativas">very</span> <span class="hps" title="Clique para mostrar traduções alternativas">good</span> <span class="hps" title="Clique para mostrar traduções alternativas">and</span> <span class="hps" title="Clique para mostrar traduções alternativas">helped</span> <span class="hps" title="Clique para mostrar traduções alternativas">me</span> <span class="hps" title="Clique para mostrar traduções alternativas">a lot</span><span title="Clique para mostrar traduções alternativas">,</span> <span class="hps" title="Clique para mostrar traduções alternativas">it was</span> <span class="hps" title="Clique para mostrar traduções alternativas">exactly</span> <span class="hps" title="Clique para mostrar traduções alternativas">what</span> <span class="hps" title="Clique para mostrar traduções alternativas">I</span> <span class="hps" title="Clique para mostrar traduções alternativas">needed</span><span title="Clique para mostrar traduções alternativas">.</span><span class="hps" title="Clique para mostrar traduções alternativas">Sorry</span> <span class="hps" title="Clique para mostrar traduções alternativas">my</span> <span class="hps" title="Clique para mostrar traduções alternativas">bad</span> <span class="hps" title="Clique para mostrar traduções alternativas">English</span><span title="Clique para mostrar traduções alternativas">,</span> <span class="hps" title="Clique para mostrar traduções alternativas">I had</span> <span class="hps" title="Clique para mostrar traduções alternativas">to</span> <span class="hps" title="Clique para mostrar traduções alternativas">appeal</span> <span class="hps" title="Clique para mostrar traduções alternativas">to</span> <span class="hps" title="Clique para mostrar traduções alternativas">the google translator</span><span title="Clique para mostrar traduções alternativas">.</span> <span class="hps" title="Clique para mostrar traduções alternativas">Maybe</span> <span class="hps" title="Clique para mostrar traduções alternativas">not</span> <span class="hps" title="Clique para mostrar traduções alternativas">100</span><span title="Clique para mostrar traduções alternativas">% correct</span><span title="Clique para mostrar traduções alternativas">.</span></span></p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment6278 eduaguiar281 http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Thu, 09 Jun 2011 22:52:53 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Issue resolved using mediator.</p> <p>Thanks, moakley</p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment5327 moakley http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Fri, 14 Jan 2011 19:38:37 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>I need the edit view model to call a web service and return data when completed.  No problem with that.  From the view model I then need to check the results of the web service call and then close if the results are good.  So from the edit view model I somehow need to tell the view to close.  Suggestions?  </p> <p>Thanks, moakley</p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment5302 moakley http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Tue, 11 Jan 2011 16:48:29 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Hi Jim,</p> <p>Sorry about the late reply. First about the RIA Services: Using RIA Services with my demo is not so difficult. All database (RIA service) calls should be placed in the PersonModel - the PersonModel should create a new instance (internally) of the RIA context and should expose methods for Load, Insert, Delete and Save. Here is the tricky moment,  in WCF RIA all exposed business objects implements IEditableObject automatically. All changes are tracked in an EntityChangeSet object, and the changes are submitted collectively when you call SubmitChanges method of your domain context (respectively rejected, when you call the RejectChanges method).</p> <p>About the second issue, I'm afraid I'm not able to help you unless I see some sample code.</p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment5061 ppopadiyn http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Mon, 13 Dec 2010 09:08:26 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Hi ppopadiyn,</p> <p>I cloned your logic and changed it to become an option on menu.  It worked fine first time entering the option but it crashed at "this.DataContext = value;" on the MainPage (which I changed to become an option instead of the startup page).  Do you have any idea how to fix it?  Thansk.</p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment5059 Jim http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Sun, 12 Dec 2010 00:46:16 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Hi <a href="http://www.silverlightshow.net/Profile.aspx?userId=0f58cf98-55a0-4fff-9f40-d66448768b7e" id="ctl00_cphMiddle_ContentPlaceHolderContent_itemComments_dlstComments_ctl72_hlnkCommentAuthor"><span style="color: #1ca0f2;">ppopadiyn</span></a>,</p> <p>Can you give me some tips if I wanted to incorporate RIA service in your sample, what are the areas I should touch?  How do I change PersonModel to pull data from domain service?</p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment5025 Jim http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Thu, 02 Dec 2010 17:37:24 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Hi Jim,</p> <p>Sorry but I am not a VB guy :(. However I would recommend you to use the following <a href="http://www.tangiblesoftwaresolutions.com/Product_Details/Instant_VB.html?gclid=CK_cyZGHtKUCFc4H3wodF2kWYQ">C# to VB converter</a>. I'm using the demo version whenever I need to convert code and it works pretty reliable.</p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4931 ppopadiyn http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Mon, 22 Nov 2010 11:01:41 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Hi <a href="http://www.silverlightshow.net/Profile.aspx?userId=0f58cf98-55a0-4fff-9f40-d66448768b7e" id="ctl00_cphMiddle_ContentPlaceHolderContent_itemComments_dlstComments_ctl72_hlnkCommentAuthor"><span style="color: #1ca0f2;">ppopadiyn</span></a>,</p> <p>Is there a VB version for download?  I tried to convert it from C# to VB but failed.</p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4926 Jim http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Fri, 19 Nov 2010 22:11:17 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Hi Jim,</p> <p>Thank you for your interest in the article. The project Framework is nothing special. It just contains common (reusable) classes. The purpose is at some point this library (these classes) to be re-used easy from another Silverlight project.</p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4891 ppopadiyn http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Thu, 18 Nov 2010 09:54:14 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Hello,</p> <p>It's very impressive and thank you for sharing your work.</p> <p>My knowledge is Silverlight, MVVM is very limited.  Can you tell what is required to create the project "Framework".  Perhaps this is not target for beginner, if there is step by step instructions it will be wonderful.</p> <p>Thanks anyway.</p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4885 Jim http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Wed, 17 Nov 2010 23:06:41 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Hi J,</p> <p>Happy to hear that you got things working ;)</p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4494 ppopadiyn http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Fri, 17 Sep 2010 08:15:19 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Hi Pencho,</p> <p>I looked through some articles on MEF and was able to get things working. </p> <p>Thanks again for your efforts !</p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4490 J http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Fri, 17 Sep 2010 01:24:02 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Thanks, Pencho. I was trying to sort the rest out by myself and not have to bother you again, but have just one question and some comments.</p> <p>1. Exactly where should the  this.DeleteControl.Value be placed?</p> <p>2. I get the following messages in the ModalDialogWorker class after changing the parameter IModal modalview to the Lazy<T> version:</p> <p><br /> </p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal helvetica;">'System.Lazy<Framework.IModalView>' does not contain a definition for 'Closed' and no extension method 'Closed' accepting a first argument of type 'System.Lazy<Framework.IModalView>' could be found (are you missing a using directive or an assembly reference?)</p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal helvetica;"></p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal helvetica;"></p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal helvetica;">'System.Lazy<Framework.IModalView>' does not contain a definition for 'DataContext' and no extension method 'DataContext' accepting a first argument of type 'System.Lazy<Framework.IModalView>' could be found (are you missing a using directive or an assembly reference?)</p> <p><br /> </p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal helvetica;">And in the <span style="font-family: 'comic sans ms'; font-size: 9px;">OnDeleteContactCommandExecute </span>block I get the following 2 messages:</p> <div><br /> </div> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal helvetica;">The best overloaded method match for 'Framework.IModalDialogWorker.ShowDialog<.....Contact>(Framework.IModalDialog, Framework.IModalView, ......Contact, System.Action<.......Contact>)' has some invalid arguments</p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal helvetica;"></p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal helvetica;"></p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal helvetica;">cannot convert from 'System.Lazy<Framework.IModalView>' to 'Framework.IModalView'</p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal helvetica;"></p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal helvetica;"></p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal helvetica;">PHEW! I do think i need to take some time to read up on MEF.  If it is too much bother for you, i can switch to another implementation that does not use MEF for now, and convert later down the road.</p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal helvetica;"></p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal helvetica;">Thanks !</p> <br /> <p><br /> </p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4479 J http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Thu, 16 Sep 2010 02:35:32 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Hi again J,</p> <p>Excellent case, you are doing nothing wrong. However there are several special features in mef, you should be familiar with. For example, when you call CompositionInitialized.SatisfyImport in your main control, this will create a new instance of your main viewmodel. On the next step, mef will try to satisfy all imports in your viewmodel. In your case probably it will need to create a new instance of the DeleteControl. Next, all imports in the DeleteControl will be satisfied. For example, your DeleteControl says: "Hey i want to import a string property to display on the UI" - this is DeleteContactWarning property. And of course, mef will try to find the corresponding export, which is located in your view model. And considering that your don't have selectedContact, it will throw NullReferenceExpcetion.</p> <p>As you can note, all graph of objects are created immediately after the calling of SatisfyImport. If you have a long and complex graph of objects this can be expensive and unnecessary. In your case, this also is causing an exception. That's why mef supports so called lazy exports/imports. In order to use it all you need to do is to import an [System.Lazy<T>] instead of [T] directly.</p> <p>So, first in your ViewModel, instead of importing directly DeleteControl, you should have something like this: </p> <div style="border: 1px solid #7f9db9; overflow-y: auto;" class="reCodeBlock"> <div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #000000;">[Import( ModalViewNames.DeleteControlName )]</code></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #006699; font-weight: bold;">public</code> <code style="color: #000000;">Lazy<IModalView> DeleteControl</code></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #000000;">{</code></span></div> <div style="background-color: #f8f8f8;"><span><code>    </code><span style="margin-left: 12px ! important;"><code style="color: #006699; font-weight: bold;">get</code><code style="color: #000000;">;</code></span></span></div> <div style="background-color: #ffffff;"><span><code>    </code><span style="margin-left: 12px ! important;"><code style="color: #006699; font-weight: bold;">set</code><code style="color: #000000;">;</code></span></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #000000;">}</code></span></div> </div> <p></p> <p>When you use the DeleteControl, you should write something like this</p> <div style="border: 1px solid #7f9db9; overflow-y: auto;" class="reCodeBlock"> <div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #006699; font-weight: bold;">this</code><code style="color: #000000;">.DeleteControl.Value</code></span></div> </div> In this case the instantiation of the DeleteControl will be delayed, until this.DeleteControl.Value is invoked. I suggest to put breakpoint in the DeleteControl constructor in the both cases, to see the difference. <p></p> <p>Also you should slightly modify the logic about the constructing of the DeleteContactWarning message. Instead of import/export <strong>properties</strong>, you should import/export <strong>methods</strong>.</p> <p>First, in your view model, you should construct the message in a method instead of property:</p> <div style="border: 1px solid #7f9db9; overflow-y: auto;" class="reCodeBlock"> <div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #008200;">//[Export( "CustomDeleteMessage" )]</code></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #008200;">//public string DeleteMessage</code></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #008200;">//{</code></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #008200;">//    get</code></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #008200;">//    {</code></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #008200;">//        return "Confirm permanent removal of " + this.SelectedPerson.Name;</code></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #008200;">//    }</code></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #008200;">//}</code></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"> </span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #000000;">[Export( </code><code style="color: blue;">"CustomDeleteMessage"</code> <code style="color: #000000;">)]</code></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #006699; font-weight: bold;">public</code> <code style="color: #006699; font-weight: bold;">string</code> <code style="color: #000000;">GetDeleteMessage()</code></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #000000;">{</code></span></div> <div style="background-color: #ffffff;"><span><code>    </code><span style="margin-left: 12px ! important;"><code style="color: #006699; font-weight: bold;">return</code> <code style="color: blue;">"Confirm permanent removal of "</code> <code style="color: #000000;">+ </code><code style="color: #006699; font-weight: bold;">this</code><code style="color: #000000;">.SelectedPerson.Name;</code></span></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #000000;">}</code></span></div> </div> Next, in the DeleteControl, you should have something like this:<br /> <div style="border: 1px solid #7f9db9; overflow-y: auto;" class="reCodeBlock"> <div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #006699; font-weight: bold;">public</code> <code style="color: #000000;">DeleteControl()</code></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #000000;">{</code></span></div> <div style="background-color: #ffffff;"><span><code>    </code><span style="margin-left: 12px ! important;"><code style="color: #000000;">InitializeComponent();</code></span></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"> </span></div> <div style="background-color: #ffffff;"><span><code>    </code><span style="margin-left: 12px ! important;"><code style="color: #006699; font-weight: bold;">this</code><code style="color: #000000;">.Loaded += ( s, a ) =></code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>    </code><span style="margin-left: 12px ! important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #ffffff;"><span><code>        </code><span style="margin-left: 24px ! important;"><code style="color: #006699; font-weight: bold;">if</code> <code style="color: #000000;">( </code><code style="color: #006699; font-weight: bold;">this</code><code style="color: #000000;">.CustomDeleteMessageAction != </code><code style="color: #006699; font-weight: bold;">null</code> <code style="color: #000000;">)</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>        </code><span style="margin-left: 24px ! important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px ! important;"><code style="color: #006699; font-weight: bold;">this</code><code style="color: #000000;">.tbMessage.Text = </code><code style="color: #006699; font-weight: bold;">this</code><code style="color: #000000;">.CustomDeleteMessageAction();</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>        </code><span style="margin-left: 24px ! important;"><code style="color: #000000;">}</code></span></span></div> <div style="background-color: #ffffff;"><span><code>    </code><span style="margin-left: 12px ! important;"><code style="color: #000000;">};</code></span></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #000000;">}</code></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"> </span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #008200;">//[Import( "CustomDeleteMessage" )]</code></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #008200;">//public string CustomDeleteMessage</code></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #008200;">//{</code></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #008200;">//    set</code></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #008200;">//    {</code></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #008200;">//        this.tbMessage.Text = value;</code></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #008200;">//    }</code></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #008200;">//}</code></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"> </span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #000000;">[Import( </code><code style="color: blue;">"CustomDeleteMessage"</code> <code style="color: #000000;">)]</code></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #006699; font-weight: bold;">public</code> <code style="color: #000000;">Func<</code><code style="color: #006699; font-weight: bold;">string</code><code style="color: #000000;">> CustomDeleteMessageAction</code></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #000000;">{</code></span></div> <div style="background-color: #f8f8f8;"><span><code>    </code><span style="margin-left: 12px ! important;"><code style="color: #006699; font-weight: bold;">get</code><code style="color: #000000;">;</code></span></span></div> <div style="background-color: #ffffff;"><span><code>    </code><span style="margin-left: 12px ! important;"><code style="color: #006699; font-weight: bold;">set</code><code style="color: #000000;">;</code></span></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #000000;">}</code></span></div> </div> Again I suggest to try both of the solutions (import/export properties and methods) and see the difference. When you have import/export properties, it won't throw an exception, but i won't work correctly. E.g. try to delete more than one record - the delete message won't be construct correctly. If you use methods, everything should be o.k. <p></p> <p>Hope this help.</p> <p></p> <p></p> <p></p> <p></p> <p></p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4473 ppopadiyn http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Wed, 15 Sep 2010 09:20:18 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <span style="color: #535353; font-family: arial, verdana, tahoma, sans-serif; font-size: 14px; line-height: 20px;">Hi again, Ppopadyin</span><br /> <div><span style="color: #535353; font-family: arial, verdana, tahoma, sans-serif; font-size: 14px; line-height: 20px;">I used your code and it worked. I wanted to add further customization but due to the following line in my main control</span></div> <div><span style="color: #535353; font-family: arial, verdana, tahoma, sans-serif; font-size: 14px; line-height: 20px;"></span></div> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal 'comic sans ms';">  <span style="color: #1738f5;">if</span> (!GalaSoft.MvvmLight.<span style="color: #32a2ba;">ViewModelBase</span>.IsInDesignModeStatic)</p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal 'comic sans ms';">            {</p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal 'comic sans ms'; color: #008f29;"><span style="color: #000000;">                </span>// Use MEF To load the View Model                </p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal 'comic sans ms';">                <span style="color: #32a2ba;">CompositionInitializer</span>.SatisfyImports(<span style="color: #1738f5;">this</span>);</p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal 'comic sans ms';">            }</p> <div><br /> </div> <div><span style="color: #535353; font-family: arial, verdana, tahoma, sans-serif; font-size: 14px; line-height: 20px;">the entire ViewModel is loaded. I placed a variant of your code (not in the Constants.cs, as suggested) but in my ViewModel like so:</span></div> <div><span style="color: #535353; font-family: arial, verdana, tahoma, sans-serif; font-size: 14px; line-height: 20px;"></span></div> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal 'comic sans ms'; color: #b52422;"><span style="color: #000000;"> [</span><span style="color: #32a2ba;">Export</span><span style="color: #000000;">(</span>"CustomDeleteMessage"<span style="color: #000000;">)]</span></p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal 'comic sans ms';">        <span style="color: #1738f5;">public</span> <span style="color: #1738f5;">string</span> DeleteContactWarning</p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal 'comic sans ms';">        {</p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal 'comic sans ms';">            <span style="color: #1738f5;">get</span></p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal 'comic sans ms';">            {</p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal 'comic sans ms';">                <span style="color: #1738f5;">return</span></p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal 'comic sans ms'; color: #b52422;"><span style="color: #000000;">                    </span>"Confirm permanent removal of "<span style="color: #000000;">  +</span></p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal 'comic sans ms';">                <span style="color: #1738f5;">this</span>.selectedContact.FirstName + <span style="color: #b52422;">" "</span> + <span style="color: #1738f5;">this</span>.selectedContact.LastName;</p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal 'comic sans ms';">            }</p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal 'comic sans ms';">        }</p> <div><br /> </div> <div><span style="color: #535353; font-family: arial, verdana, tahoma, sans-serif; font-size: 14px; line-height: 20px;">Unfortunately, this code segment is being executed before any Contact is selected. So i get a null exception message.</span></div> <div><span style="color: #535353; font-family: arial, verdana, tahoma, sans-serif; font-size: 14px; line-height: 20px;">This is how my ViewModel starts:</span></div> <div><span style="color: #535353; font-family: arial, verdana, tahoma, sans-serif; font-size: 14px; line-height: 20px;"></span></div> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal 'comic sans ms';"> [<span style="color: #32a2ba;">Export</span>(<span style="color: #32a2ba;">ViewModelTypes</span>.EmpContactViewModel)]   </p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal 'comic sans ms'; color: #32a2ba;"><span style="color: #000000;">    </span><span style="color: #1738f5;">public</span><span style="color: #000000;"> </span><span style="color: #1738f5;">class</span><span style="color: #000000;"> </span>EmpContactViewModel<span style="color: #000000;">: </span>ViewModelBase<span style="color: #000000;">, </span>IPartImportsSatisfiedNotification</p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal 'comic sans ms';">    {</p> <div><br /> </div> <div><span style="color: #535353; font-family: arial, verdana, tahoma, sans-serif; font-size: 14px; line-height: 20px;">How can i delay the call to the DeleteContactWarning string till my SelectedContact has been set? </span></div> <div><span style="color: #535353; font-family: arial, verdana, tahoma, sans-serif; font-size: 14px; line-height: 20px;">I tested the code after commenting out the SelectedContact names line, and i was able to get the custom message (minus the name, of course, to show in the  dialog)</span></div> <div><span style="font-family: arial, verdana, tahoma, sans-serif; color: #535353; font-size: 14px; line-height: 20px;">What am i doing wrong here?</span></div> <div><span style="font-family: arial, verdana, tahoma, sans-serif; color: #535353; font-size: 14px; line-height: 20px;"><br /> </span></div> <div><span style="font-family: arial, verdana, tahoma, sans-serif; color: #535353; font-size: 14px; line-height: 20px;">Thanks again</span></div> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4471 J http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Wed, 15 Sep 2010 02:56:58 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Hello J,</p> <p><a href="http://www.silverlightshow.net/Storage/Users/ppopadiyn/ModalDialogs_IEditableObject_MVVM_SL4/SourceCode/Demo_CustomMessage.zip">Here </a>is a modified demo showing you how to pass custom delete message by using mef. Take a look at the following classes:</p> <ul> <li>Code - behind for DeleteControl.xaml, I've added an additional property named "<em>CustomDeleteMessage</em>". See the [Import] attribute.</li> <li>I've created an additional class named StringConfigurator - it is located in the Constants.cs file. There, the [Export] attribute is used. Note that, you should pass a contract name for both of the attributes. It must be the same in order to work.</li> </ul> <p>Another possible solution is to create an additional class named DeleteControlViewModel - this will be a view model for the delete control. And in the DeleteControl, you will bind the TextBox.Text property to the corresponding string property of the DeleteControlViewModel. See the PersonViewModel, in the OnDeletePersonCommandExecute method. Instead of passing this.SelectedPerson as a DataContext to the DeleteControl you will pass a new instance of the DeleteControlViewModel. Personally I prefer the second solution. But the first one is also playable. </p> <p>Please if you have any further questions do not hesitate to contact me.</p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4459 ppopadiyn http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Tue, 14 Sep 2010 08:28:39 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <div><br /> </div> <p>Ppopadyin, I still need help with getting  this example to work when sending a customized message to the dialog box using MEF. Can u give me some code. Looked at the link you provided but I'm still not getting it.</p> <p>Thanks</p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4458 J http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Tue, 14 Sep 2010 03:49:44 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Thanks ppopadiyn! </p> <p>Please ignore the duplicate post.</p> <p>Cheers!</p> <p> </p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4455 J http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Mon, 13 Sep 2010 18:35:35 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Hello Jay,</p> <p>I can think of three possible solutions</p> <ul> <li>As you guessed, a parameter in the constructor of the control.</li> <li>Add an additional property of type Hashtable (or generic Dictionary) in the IModalView interface.</li> <li>If you want to use MEF, you could define "Property Imports" or  use "Importing Constructor". Find more info <a href="http://mef.codeplex.com/wikipage?title=Declaring%20Imports&referringTitle=Guide">here</a>.</li> </ul> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4451 ppopadiyn http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Mon, 13 Sep 2010 09:54:17 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>If I wanted to pass a string parameter to the DeleteControl in this situation, how would I go about it? I was thinking of passing a customized warning message to the control. I added the parameter in the constructor like this: </p> <p> public DeleteControl (string myMessage)</p> <div><br /> </div> <p><br /> </p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4450 Jay http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Mon, 13 Sep 2010 06:21:09 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Great post!  Your demo worked great. </p> <p>I tried to use sections of it in my application. I keep getting the error message saying [Type of ......ModalDialog is not CLS_Compliant]. Any ideas ?</p> <p><br /> </p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal 'comic sans ms'; color: #32a2ba;"><span style="color: #000000;"> [</span>Import<span style="color: #000000;">]</span></p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal 'comic sans ms';">        <span style="color: #1738f5;">public</span> <span style="color: #32a2ba;">IModalDialog</span> ModalDialog</p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal 'comic sans ms';">        {</p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal 'comic sans ms';">            <span style="color: #1738f5;">get</span>;</p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal 'comic sans ms';">            <span style="color: #1738f5;">set</span>;</p> <p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal 'comic sans ms';">        }</p> <div><br /> </div> <br /> <p><br /> </p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4408 jay http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Mon, 06 Sep 2010 21:18:11 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 well done http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4338 stephan http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Thu, 26 Aug 2010 15:17:50 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>There is a bug in your sample.</p> <p><br /> </p> <ol> <li>Select a Person.</li> <li>Click Edit.</li> <li>Modify the Name, and leave the focus in the Name text box.</li> <li>Click the X in the upper right of the dialog to close it.</li> <li>The Name was updated when it shouldn't have been.</li> </ol> <div><br /> </div> <p><br /> </p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4151 Brian http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Wed, 04 Aug 2010 16:39:22 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 Thank for your comment! That's what I realy need. http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4145 Calabonga http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Wed, 04 Aug 2010 03:20:38 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 Thanks! http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4138 dbis http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Mon, 02 Aug 2010 20:26:59 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Hi dbis</p> <p>Setting the <strong>DialogResult</strong> property of the <strong>ChildWindow</strong>, automatically close it (that is the behavior of the ChildWindow). That happens in the ModalDialogWorker, line 40.</p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4130 ppopadiyn http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Mon, 02 Aug 2010 08:01:03 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 ppopadyyn, could you please clarify how you close modal dialog? <title>Snippet</title> <pre style="font-family: consolas;"><span style="color: green;">modalDialog.Close()</span> is commented out</pre> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4108 dbis http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Mon, 02 Aug 2010 00:21:25 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>ppopadyyn</p> <p>Thanks for the prompt reply, okay I will look into further and hopefully resolve.</p> <p>If anyone else has converted this code to Vb.net  please get back to me.</p> <p>Thanks</p> <p><br /> </p> <p><br /> </p> <p><br /> </p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4029 Richard http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Wed, 21 Jul 2010 13:15:11 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Hi Richard,</p> <p>Sorry but I am not an expert in VB.NET. As regards your question about the ExtendedChildWindow and IModalDialog. The ExtendedChildWindow class derives from ChildWindow and implements the IModalDialog interface. "<em>it should have a Close() method - the C# version does not</em>" - you are absolutely right there must be a Close method in the ExtendedChildWindow dialog, but it doesn't exists. However the base ChildWindow class has a Close method, or in other words the Close method is implemented in the base ChildWindow class, and the compiler obviously is pretty smart :) to recognize this. Just for a test you could rename the "Close" method in the C# code, for example to "Close2" and see the result, now you will have a compiler error.</p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4027 ppopadiyn http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Wed, 21 Jul 2010 11:37:34 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Hi</p> <p>I've converted your code to vb.net but am getting issues. I'm not an expert on OOP/classes...this is 2 examples errors (about 19 similiar)</p> <p>Class 'PersonViewModel' must implement 'Sub OnImportsSatisfied()' for interface 'System.ComponentModel.Composition.IPartImportsSatisfiedNotification'.  ..\...\Demo\ViewModels\PersonViewModel.vb<span class="Apple-tab-span" style="white-space: pre;"> </span></p> <p><span class="Apple-tab-span" style="white-space: pre;"> </span>Class 'ExtendedChildWindow' must implement 'Sub Close()' for interface 'Framework.IModalDialog'.<span class="Apple-tab-span" style="white-space: pre;"> </span>Views\ExtendedChildWindow.vb<span class="Apple-tab-span" style="white-space: pre;"> </span></p> <div><br /> </div> My understanding is that as the ExtendedChildWindow implements Framework.IModalDialog<br />  it should have a Close() method - the C# version does not - likewise the OnImportsSatisfied sub exists in PersonViewModel<br />  but does not have the keyword 'Implements IPartImportsSatisfiedNotification' attached to it (C# version has this missing as well but no compilation error). If I add Implements IPartImportsSatisfiedNotification to the OnImportsSatisfied<br />  sub I still get compilation error - I am now confused.  Anyone one of you guru's shed some light/advice on this (obviouslt some difference in conversion from C# to Vb.net??) <p><br /> </p> <p>Great article.</p> <p>Richard</p> <p><br /> </p> <br /> <p><br /> </p> <p><br /> </p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4026 Richard http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Wed, 21 Jul 2010 11:25:11 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Hello Calabonga,</p> <p>Fortunately, in WCF RIA all exposed business objects implements IEditableObject automatically. All changes are tracked in an EntityChangeSet object, and the changes are submitted collectively when you call SubmitChanges method of your domain context (respectively rejected, when you call the RejectChanges method). So you could use the same approach with the modal dialogs and mvvm. The only difference is that you should work directly with your domain context.</p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4025 ppopadiyn http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Wed, 21 Jul 2010 10:53:55 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Very good article! Thanks for your shared code.</p> <p>But what about MVVM + RIA Services modal dialog and IEditableObject?</p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment4006 Calabonga http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Mon, 19 Jul 2010 03:49:41 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Hi There,</p> <p>Very nice article.Good oppotunity to learn the Patterns.</p> <p>Thanks,</p> <p>Thani</p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment3733 Thanigainatahn http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Sat, 05 Jun 2010 21:02:15 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Very good article. Nice and clean solution.</p> <p>I have one question, what to do with collections (collection of objects|)?</p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment3731 Alex http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Sat, 05 Jun 2010 14:52:35 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 Hi Denis, I am very happy you find the samples useful and thanks a lot for the improvements ;) http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment3704 ppopadiyn http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Wed, 02 Jun 2010 18:43:41 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>This is a great solution and your samples help me a lot. However I've made some corrections to code:</p> <p>1. Some value comparison will work differently for reference and value types. So I've restricted Memento and Proxy with a constraint: "where T : class"</p> <p>2. Memento won't work properly for the class containing properties with non-public setters (at least for Silverlight 3). I've updated the Memento.InitializeMemento with additional check for public setter presence:</p> <p>foreach (var property in propertyInfos)<br />       {<br />         if (property.GetSetMethod() == null) continue;<br />         _storedProperties[property] = property.GetValue(originator, null);<br />       }</p> <p>Regards,</p> <p>Denis</p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment3703 Denis Vuyka http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Wed, 02 Jun 2010 18:39:24 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 Hi aitran, probably, you need pass somehow to the ViewModel instances of the implementations (for example you can create a new constructor for the view model and pass instances of the ModalDialogWorker, ModalDialog, ModalView, etc). If you don't use MEF, then this is the nature of .Net, it will not create instances of these classes and when you try to use them NullReferenceException will be thrown. Let me know if this works for you. http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment3652 ppopadiyn http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Fri, 21 May 2010 10:27:18 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 Im not using MEF for the whole solution, and I try to use IModalDialog, then it throws an exception of null in the ViewModel ModalDialogWorker <div>Please help,</div> <div>Thanks.</div> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment3651 aitran http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Fri, 21 May 2010 10:22:08 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Amazing solution. A little complex to me yet, but will continue my studies on MVVM and MEF with SL.<br /> This will realy help me a lot!</p> <p>Thanks man!</p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment3643 Andre Baltieri http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Fri, 21 May 2010 05:09:33 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 Pencho, thanks for sharing this elegant solution, source code, and well written article.... http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment3623 mike kidder http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Tue, 18 May 2010 03:23:45 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 <p>Hi,</p> <p>If you mean the modal dialogs, i agree with you that using additional user controls makes the program more complex. Maybe using directly ChildWindows is better approach ;). Thanks for advice</p> http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment3596 ppopadiyn http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Wed, 12 May 2010 17:16:48 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 This is way too much code.  This is really over complicating things.  Keep it simple. http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment3595 simple http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Wed, 12 May 2010 17:08:36 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 Nice Article !!!!! http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment3588 Balaji http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Wed, 12 May 2010 07:57:27 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 Very nice. I've just started creating a bunch of SL4 ModalDialogs for a project..your article was timely. http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment3581 s. singh http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Tue, 11 May 2010 18:46:27 GMT RE: ModalDialogs, IEditableObject and MVVM in Silverlight 4 Very nice article.  Great work. http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx#comment3579 WPFDeveloper http://www.silverlightshow.net/items/ModalDialogs-IEditableObject-and-MVVM-in-Silverlight-4.aspx Tue, 11 May 2010 14:04:22 GMT