<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Modal dialogs with MVVM and Silverlight 4</title>
	<atom:link href="http://blog.roboblob.com/2010/01/19/modal-dialogs-with-mvvm-and-silverlight-4/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.roboblob.com/2010/01/19/modal-dialogs-with-mvvm-and-silverlight-4/</link>
	<description>and ideas for its refactoring...</description>
	<lastBuildDate>Fri, 03 Sep 2010 19:29:04 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: roboblob</title>
		<link>http://blog.roboblob.com/2010/01/19/modal-dialogs-with-mvvm-and-silverlight-4/comment-page-1/#comment-1503</link>
		<dc:creator>roboblob</dc:creator>
		<pubDate>Sun, 08 Aug 2010 19:08:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.roboblob.com/?p=109#comment-1503</guid>
		<description>well i disagree that this should be called IChildWindow since purpose of this entity and the service IModalDialogService is deliberately determined by its name: to show modal dialogs that block UI until user chooses some options or clicks Cancel. I like to call entities in my code with strict names, its a good practice because when entity is called with precise name then he does exactly that and you don&#039;t have temptation then to add other features to it. If you start calling classes with general names then its easy to add more functionality to them and then they soon become &#039;Swiss knife&#039; kind of classes that do everything.

If i would need non-modal dialog then i would introduce IDialog and IDialogService same as i did introduce IMessageBoxService etc.

All this may sound too strict but practice learned me that strict naming conventions lead to better code.

Hope this clarifies why i named the classes as i did.

thanks for your feedback!</description>
		<content:encoded><![CDATA[<p>well i disagree that this should be called IChildWindow since purpose of this entity and the service IModalDialogService is deliberately determined by its name: to show modal dialogs that block UI until user chooses some options or clicks Cancel. I like to call entities in my code with strict names, its a good practice because when entity is called with precise name then he does exactly that and you don&#8217;t have temptation then to add other features to it. If you start calling classes with general names then its easy to add more functionality to them and then they soon become &#8216;Swiss knife&#8217; kind of classes that do everything.</p>
<p>If i would need non-modal dialog then i would introduce IDialog and IDialogService same as i did introduce IMessageBoxService etc.</p>
<p>All this may sound too strict but practice learned me that strict naming conventions lead to better code.</p>
<p>Hope this clarifies why i named the classes as i did.</p>
<p>thanks for your feedback!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oliver Weichhold</title>
		<link>http://blog.roboblob.com/2010/01/19/modal-dialogs-with-mvvm-and-silverlight-4/comment-page-1/#comment-1501</link>
		<dc:creator>Oliver Weichhold</dc:creator>
		<pubDate>Sun, 08 Aug 2010 16:52:13 +0000</pubDate>
		<guid isPermaLink="false">http://blog.roboblob.com/?p=109#comment-1501</guid>
		<description>Wouldn&#039;t it be more appropriate to rename the interfaces from IModalWindow to IChildWindow and from IModalDialogService to IChildWindowService? Technically I don&#039;t see anything that would prevent this to be used for non-modal (modeless) dialogs as well.</description>
		<content:encoded><![CDATA[<p>Wouldn&#8217;t it be more appropriate to rename the interfaces from IModalWindow to IChildWindow and from IModalDialogService to IChildWindowService? Technically I don&#8217;t see anything that would prevent this to be used for non-modal (modeless) dialogs as well.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: roboblob</title>
		<link>http://blog.roboblob.com/2010/01/19/modal-dialogs-with-mvvm-and-silverlight-4/comment-page-1/#comment-1414</link>
		<dc:creator>roboblob</dc:creator>
		<pubDate>Wed, 04 Aug 2010 12:45:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.roboblob.com/?p=109#comment-1414</guid>
		<description>Hi Frosty,

can you send me on email webmaster [at] roboblob dot com some small example of this bug since i cannot reproduce it in my code it always fires once.
thanks!</description>
		<content:encoded><![CDATA[<p>Hi Frosty,</p>
<p>can you send me on email webmaster [at] roboblob dot com some small example of this bug since i cannot reproduce it in my code it always fires once.<br />
thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: roboblob</title>
		<link>http://blog.roboblob.com/2010/01/19/modal-dialogs-with-mvvm-and-silverlight-4/comment-page-1/#comment-1413</link>
		<dc:creator>roboblob</dc:creator>
		<pubDate>Wed, 04 Aug 2010 12:45:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.roboblob.com/?p=109#comment-1413</guid>
		<description>Thanks for posting, nice work.</description>
		<content:encoded><![CDATA[<p>Thanks for posting, nice work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: frosty</title>
		<link>http://blog.roboblob.com/2010/01/19/modal-dialogs-with-mvvm-and-silverlight-4/comment-page-1/#comment-1412</link>
		<dc:creator>frosty</dc:creator>
		<pubDate>Wed, 04 Aug 2010 12:26:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.roboblob.com/?p=109#comment-1412</guid>
		<description>Forgot to add the link to the MEF version.

http://www.dotnetpatterns.net/entries/15-MVVM-Modal-window-using-MEF</description>
		<content:encoded><![CDATA[<p>Forgot to add the link to the MEF version.</p>
<p><a href="http://www.dotnetpatterns.net/entries/15-MVVM-Modal-window-using-MEF" rel="nofollow">http://www.dotnetpatterns.net/entries/15-MVVM-Modal-window-using-MEF</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: frosty</title>
		<link>http://blog.roboblob.com/2010/01/19/modal-dialogs-with-mvvm-and-silverlight-4/comment-page-1/#comment-1411</link>
		<dc:creator>frosty</dc:creator>
		<pubDate>Wed, 04 Aug 2010 12:23:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.roboblob.com/?p=109#comment-1411</guid>
		<description>Thanks Robo,

I tried implementing the code to handle the event situation and no go.  Same issue.

I consider it a bug because if used as part of a framework, I think it should account for all situations.  I was in a hurry when I created the MEF version.  But it doesn&#039;t matter if I use shared or nonshared for exporting the viewModel, the same problem exists.

It cost me about 3 hours yesterday trying to figure out why my app was having all kinds of quircky problems and I finally remembered adding this code and it was the culprit.

Great idea but just wanted to save others the hassle I went through yesterday.

The clean up you posted, the Event handlers are different and i think that&#039;s why it doesn&#039;t work.  Everything I&#039;ve seen is you have to keep a reference to the handlers you add so you can remove them.</description>
		<content:encoded><![CDATA[<p>Thanks Robo,</p>
<p>I tried implementing the code to handle the event situation and no go.  Same issue.</p>
<p>I consider it a bug because if used as part of a framework, I think it should account for all situations.  I was in a hurry when I created the MEF version.  But it doesn&#8217;t matter if I use shared or nonshared for exporting the viewModel, the same problem exists.</p>
<p>It cost me about 3 hours yesterday trying to figure out why my app was having all kinds of quircky problems and I finally remembered adding this code and it was the culprit.</p>
<p>Great idea but just wanted to save others the hassle I went through yesterday.</p>
<p>The clean up you posted, the Event handlers are different and i think that&#8217;s why it doesn&#8217;t work.  Everything I&#8217;ve seen is you have to keep a reference to the handlers you add so you can remove them.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: roboblob</title>
		<link>http://blog.roboblob.com/2010/01/19/modal-dialogs-with-mvvm-and-silverlight-4/comment-page-1/#comment-1403</link>
		<dc:creator>roboblob</dc:creator>
		<pubDate>Tue, 03 Aug 2010 19:52:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.roboblob.com/?p=109#comment-1403</guid>
		<description>Hi Frosty,

i dont think this is really bug, since in my implementation im always creating new instance of EditUserModalDialogViewModel when im showing the dialog.
So for me Closed event never fires twice since its always different instance (while old one is garbage-collected).
If you are using always same instance of ViewModel then this could be an issue.
Nicer way to handle this would be like this:

    public void ShowDialog(IModalWindow view, TDialogViewModel viewModel, Action onDialogClose) 
    {
      view.DataContext = viewModel;
      if (onDialogClose != null)
      {
          EventHandler closedHandler = (sender, e) =&gt; onDialogClose(viewModel);

          view.Closed += (sender, e) =&gt;
                           {
                               view.Closed -= closedHandler;
                               onDialogClose(viewModel);
                           };
      }
      view.Show();            
    }

Hope it helps!
good luck with your coding.</description>
		<content:encoded><![CDATA[<p>Hi Frosty,</p>
<p>i dont think this is really bug, since in my implementation im always creating new instance of EditUserModalDialogViewModel when im showing the dialog.<br />
So for me Closed event never fires twice since its always different instance (while old one is garbage-collected).<br />
If you are using always same instance of ViewModel then this could be an issue.<br />
Nicer way to handle this would be like this:</p>
<p>    public void ShowDialog(IModalWindow view, TDialogViewModel viewModel, Action onDialogClose)<br />
    {<br />
      view.DataContext = viewModel;<br />
      if (onDialogClose != null)<br />
      {<br />
          EventHandler closedHandler = (sender, e) =&gt; onDialogClose(viewModel);</p>
<p>          view.Closed += (sender, e) =&gt;<br />
                           {<br />
                               view.Closed -= closedHandler;<br />
                               onDialogClose(viewModel);<br />
                           };<br />
      }<br />
      view.Show();<br />
    }</p>
<p>Hope it helps!<br />
good luck with your coding.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: frosty</title>
		<link>http://blog.roboblob.com/2010/01/19/modal-dialogs-with-mvvm-and-silverlight-4/comment-page-1/#comment-1402</link>
		<dc:creator>frosty</dc:creator>
		<pubDate>Tue, 03 Aug 2010 19:24:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.roboblob.com/?p=109#comment-1402</guid>
		<description>Here&#039;s a link to the sample I worked with.  Again note, the views don&#039;t show up properly in the designer as the code is.  But it does use MEF versus Unity.  I&#039;ll let somebody else solve the blendability problem.  Or send me suggestions and I&#039;ll add it to this.

Also, I have a fix in this sample for the close event I mentioned above.  

There&#039;s got to be a better way but this cost me some time tracking it down and had to come up with something and move on.

Thanks.</description>
		<content:encoded><![CDATA[<p>Here&#8217;s a link to the sample I worked with.  Again note, the views don&#8217;t show up properly in the designer as the code is.  But it does use MEF versus Unity.  I&#8217;ll let somebody else solve the blendability problem.  Or send me suggestions and I&#8217;ll add it to this.</p>
<p>Also, I have a fix in this sample for the close event I mentioned above.  </p>
<p>There&#8217;s got to be a better way but this cost me some time tracking it down and had to come up with something and move on.</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: frosty</title>
		<link>http://blog.roboblob.com/2010/01/19/modal-dialogs-with-mvvm-and-silverlight-4/comment-page-1/#comment-1401</link>
		<dc:creator>frosty</dc:creator>
		<pubDate>Tue, 03 Aug 2010 19:11:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.roboblob.com/?p=109#comment-1401</guid>
		<description>You&#039;ve got a bug in your ModalDialogService class.

You continual subscribe to the Close event and never unsubscribe.

Set a breakpoint in your MainPageViewModel at this point.

this.ShowUserCommand = 
              new DelegateCommand(userInstanceToEdit =&gt;
                                      {
                                          this.modalDialogService.ShowDialog(_editUserDialog, new EditUserModalDialogViewModel
                                                                            {
                                                                              User = userInstanceToEdit
                                                                            },
                                                                            returnedViewModelInstance =&gt;
                                                                            {
                                                                                if (_editUserDialog.DialogResult.HasValue &amp;&amp; _editUserDialog.DialogResult.Value)
                                                                              {
                                                                                //var oldPos = this.Users.IndexOf(userInstanceToEdit);
                                                                                //this.Users.RemoveAt(oldPos);
                                                                                //this.Users.Insert(oldPos, returnedViewModelInstance.User);
                                                                              }
                                                                            });
                                       });

Click the Edit button on an item.  Each time you click the edit button, it registers for close and this code will fire ever how many times a user has clicked the edit button.

For now, I&#039;ve created a List in my IModalWindow interface that I make the View implement. The code in the ShowDialog function that takes in onDialogClose looks like this.

public void ShowDialog(IModalWindow view, TDialogViewModel viewModel, Action onDialogClose) 
    {
        view.DataContext = viewModel;
        if (onDialogClose != null)
        {
           
            foreach (var evt in view.ClosedSubscribers)
            {
                view.Closed -= evt;
            }

            view.ClosedSubscribers.Clear();

            EventHandler ev = (sender, e) =&gt; onDialogClose(viewModel);
            view.Closed += ev;
            view.ClosedSubscribers.Add(ev);
        }

        view.Show();            
    }</description>
		<content:encoded><![CDATA[<p>You&#8217;ve got a bug in your ModalDialogService class.</p>
<p>You continual subscribe to the Close event and never unsubscribe.</p>
<p>Set a breakpoint in your MainPageViewModel at this point.</p>
<p>this.ShowUserCommand =<br />
              new DelegateCommand(userInstanceToEdit =&gt;<br />
                                      {<br />
                                          this.modalDialogService.ShowDialog(_editUserDialog, new EditUserModalDialogViewModel<br />
                                                                            {<br />
                                                                              User = userInstanceToEdit<br />
                                                                            },<br />
                                                                            returnedViewModelInstance =&gt;<br />
                                                                            {<br />
                                                                                if (_editUserDialog.DialogResult.HasValue &amp;&amp; _editUserDialog.DialogResult.Value)<br />
                                                                              {<br />
                                                                                //var oldPos = this.Users.IndexOf(userInstanceToEdit);<br />
                                                                                //this.Users.RemoveAt(oldPos);<br />
                                                                                //this.Users.Insert(oldPos, returnedViewModelInstance.User);<br />
                                                                              }<br />
                                                                            });<br />
                                       });</p>
<p>Click the Edit button on an item.  Each time you click the edit button, it registers for close and this code will fire ever how many times a user has clicked the edit button.</p>
<p>For now, I&#8217;ve created a List in my IModalWindow interface that I make the View implement. The code in the ShowDialog function that takes in onDialogClose looks like this.</p>
<p>public void ShowDialog(IModalWindow view, TDialogViewModel viewModel, Action onDialogClose)<br />
    {<br />
        view.DataContext = viewModel;<br />
        if (onDialogClose != null)<br />
        {</p>
<p>            foreach (var evt in view.ClosedSubscribers)<br />
            {<br />
                view.Closed -= evt;<br />
            }</p>
<p>            view.ClosedSubscribers.Clear();</p>
<p>            EventHandler ev = (sender, e) =&gt; onDialogClose(viewModel);<br />
            view.Closed += ev;<br />
            view.ClosedSubscribers.Add(ev);<br />
        }</p>
<p>        view.Show();<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: roboblob</title>
		<link>http://blog.roboblob.com/2010/01/19/modal-dialogs-with-mvvm-and-silverlight-4/comment-page-1/#comment-1347</link>
		<dc:creator>roboblob</dc:creator>
		<pubDate>Sat, 31 Jul 2010 16:13:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.roboblob.com/?p=109#comment-1347</guid>
		<description>Hi Saheer,

in my opinion there is nothing wrong with showing multiple levels of modal dialogs from architecture perspective but it is little weird from usability standpoint (but thats another question).
Your code to show dialog from other dialog looks ok except of the part where you are manually creating EditUserModalDialogViewModel (using the new keyword).

I think this should be avoided and you should not manually create instances of classes (except for builtin .net classes) and you should instead always use Service Locator or Dependency Injection patterns to get new instances of your ViewModels.

If you need to manually create a ViewModel then at least &#039;ask&#039; the Service Locator for the instance of the ViewModel and then set it up and use it how you want. Something Like this:

var viewModel = ServiceLocator.Instance.Get&lt;EditUserModalDialogViewModel&gt;();
this.modalDialogService.ShowDialog(dialog, viewModel);

this way you delegate the responsibility of creating Viewmodel to the centralized service (in this case its ServiceLocator) and then if later you have some changes in the constructor of that ViewModel its not your problem, ServiceLocator will handle this for you and you dont need to change your code.

If you want to see how Service Locator works check my code examples im always using it (underneath the covers of Service Locator im using Microsoft Unity IOC to create those instances).

Hope this helps...
Thanks for your feedback.
Cheers!</description>
		<content:encoded><![CDATA[<p>Hi Saheer,</p>
<p>in my opinion there is nothing wrong with showing multiple levels of modal dialogs from architecture perspective but it is little weird from usability standpoint (but thats another question).<br />
Your code to show dialog from other dialog looks ok except of the part where you are manually creating EditUserModalDialogViewModel (using the new keyword).</p>
<p>I think this should be avoided and you should not manually create instances of classes (except for builtin .net classes) and you should instead always use Service Locator or Dependency Injection patterns to get new instances of your ViewModels.</p>
<p>If you need to manually create a ViewModel then at least &#8216;ask&#8217; the Service Locator for the instance of the ViewModel and then set it up and use it how you want. Something Like this:</p>
<p>var viewModel = ServiceLocator.Instance.Get<editusermodaldialogviewmodel>();<br />
this.modalDialogService.ShowDialog(dialog, viewModel);</p>
<p>this way you delegate the responsibility of creating Viewmodel to the centralized service (in this case its ServiceLocator) and then if later you have some changes in the constructor of that ViewModel its not your problem, ServiceLocator will handle this for you and you dont need to change your code.</p>
<p>If you want to see how Service Locator works check my code examples im always using it (underneath the covers of Service Locator im using Microsoft Unity IOC to create those instances).</p>
<p>Hope this helps&#8230;<br />
Thanks for your feedback.<br />
Cheers!</editusermodaldialogviewmodel></p>
]]></content:encoded>
	</item>
</channel>
</rss>
