• Shortcuts : 'n' next unread feed - 'p' previous unread feed • Styles : 1 2

» Publishers, Monetize your RSS feeds with FeedShow:  More infos  (Show/Hide Ads)


Date: Saturday, 20 Mar 2010 15:40
Ward Bell recently published a very thought provoking review/critique of my book Advanced MVVM.  In his review he dished out a compliment sandwich, with a meaty middle of constructive criticism.  I appreciate his positive feedback, and even more so the critical feedback. However, there are a few things in his post that I would like to speak to, since I disagree with some of what he said.
While planning the book, I had to make some decisions and compromises.  My overarching goal was to elucidate the complex interactions that can occur between Views and ViewModels.  I wanted the book to be brief, packed with solutions to recurring problems I’ve seen people asking about on the Web, introduce some interesting new material, and to have minimal overlap with my article about MVVM in MSDN Magazine.  I consider that MSDN article to be “part one” and the book to be “part two” of some unofficial series that I write about MVVM over time.
Another goal was to keep the BubbleBurst demo application understandable to a wide audience.  I made a point of not applying design patterns to everything that could be formalized, because that would just distract the reader from what I wanted to teach them.  Now that you have some of the back story, let’s continue.
Ward’s four main points of criticism are that my book does not cover testing, the data model, dependency injection (DI), or event aggregation.  Since my MVVM article showed how to write tests for the ViewModel layer, I did not cover it in the book.  I know that the examples in that article are not the end-all-be-all final solution to testing ViewModels.  There are certainly a million other important topics that could be discussed to no end about it.  But writing a book about unit testing was not what I set out to do.  I wanted to focus on complex interactions between Views and ViewModels, period.
I’ve had quite a few people ask why the book does not talk about using Model objects.  Aside from the fact that I covered it in the MSDN article, there are two reasons.  First, I wanted Advanced MVVM to focus on the complexities that can arise between the View and ViewModel layers.  That’s why I wrote the book.  Second, working with Model objects is not all that difficult, in my opinion.  When working on an MVVM app, I never find myself solving difficult problems related to the Model, once those classes exist.  That’s the easy part.  Why bother writing about the easy stuff in a book labeled “advanced?”  The hard part about Model objects is designing them, and my book certainly was not intended to be about domain modeling.  Also, the fact that the BubbleBurst application, which is the demo app discussed in the book, has no Model objects, made it even easier to elide the topic…
Moving on to Ward’s other points of critique, let’s talk about dependency injection.  Or, let’s not.  I chose the latter option in my book.  Why?  Dependency injection is a very important and popular topic, so it would certainly be justifiable to discuss it in a book about advanced MVVM.  On the other hand, DI is not in any way, shape, or form part of MVVM.  The two can be used together very effectively, but they are orthogonal practices.  If I wrote a book about DI, would people expect me to include a chapter about MVVM?  I highly doubt it. Like I keep saying, I wanted Advanced MVVM to focus on complex interactions between Views and ViewModels.  The point of the book was not to show how to use every cool, popular, useful technique and pattern.  Advanced MVVM is focused like a sniper on the head of some evil dictator, just waiting to fire a shot.  One shot, one kill.  One focus, one book.
Ward’s other main point of contention is that I didn’t write anything about event aggregation.  He’s correct, I did not.  I certainly could have, but that topic is irrelevant to the focus of my book.
In conclusion, everyone has their own opinion on what a book about “advanced” MVVM should/must contain.  I appreciate guys like Ward, who respectfully disagree with my opinion and voice their own interesting thoughts on the matter.  Perhaps all of this feedback will inspire me to write another book about MVVM!

Author: "Josh Smith" Tags: "Reading Material, mvvm"
Comments Send by mail Print  Save  Delicious 
Date: Tuesday, 16 Mar 2010 15:21

One of the pain points in MVVM development is controlling input focus from ViewModel objects.  A common scenario is when a validation error occurs, and focus needs to move to the control that is bound to the property in error.  This makes it easier for the user to immediately fix the validation problem.

A while ago, Dr. WPF shared a solution to the WPF Disciples that involves hijacking the VM’s IDataErrorInfo implementation and doing some hacky magic that results in focus being sent to the correct control.  While a brilliant solution, I preferred finding a more formal, less hacky solution.  This blog post presents the implementation that I’ve thrown together, with help from the WPF Disciples over the past few days.

In a ViewModel object, you must implement my IFocusMover interface.

public event EventHandler MoveFocus;

void RaiseMoveFocus(string focusedProperty)
{
var handler = this.MoveFocus;
if (handler != null)
{
var args = new MoveFocusEventArgs(focusedProperty);
handler(this, args);
}
}

The MoveFocus event should be raised when the VM object determines that input focus needs to be sent to the control bound to the ‘focused property.’  For example, if the FirstName property of an object is deemed invalid, you would call the RaiseMoveFocus method, passing “FirstName” as the focused property argument.  In the demo application, this results in the TextBox whose Text is bound to the FirstName property to get input focus.

Now let’s shift our attention to the View to see how a control is configured to be able to receive focus.  The only thing you must do is use a custom Binding object that I made, called FocusBinding.  That class relies on Philipp Sumi’s BindingDecoratorBase class, which allows you to create a custom Binding that can override the all-important ProvideValue method (inherited from MarkupExtension).

public override object ProvideValue(IServiceProvider provider)
{
DependencyObject elem;
DependencyProperty prop;
if (base.TryGetTargetItems(provider, out elem, out prop))
{ FocusController.SetFocusableProperty(elem, prop); }

return base.ProvideValue(provider);
}

You use the FocusBinding in XAML like this:

<TextBox

Text=”{jas:FocusBinding Path=FirstName, ValidatesOnDataErrors=True}”

/>

The ValidatesOnDataErrors property setting is not required, but is used in the demo app to enable support for validation via the VM’s IDataErrorInfo implementation.  All controls bound to VM properties that can be “focusable” use the FocusBinding, instead of a normal Binding.  When the VM raises its MoveFocus event, the control whose FocusBinding’s Path references the ‘focused property’ will be given input focus.

You can download the source code here.  NOTE: Rename the file extension from .DOC to .ZIP and then decompress it.  Feedback is welcome!


Author: "Josh Smith" Tags: "mvvm"
Comments Send by mail Print  Save  Delicious 
Date: Saturday, 13 Mar 2010 18:22

Every once in a while I post a recording of myself playing a piano piece that I’ve been practicing.  This time I’m performing the Allegro from Handel’s second keyboard suite.  The recording quality is not ideal, since I never invested in real recording equipment and software.  For those of you who like Baroque keyboard music, I hope you enjoy it!

Handel Keyboard Suite 2 – Allegro


Attached Media: audio/mpeg (1 345 ko)
audio/mpeg (1 -1000 ko)
audio/mpeg (1 345 ko)
Author: "Josh Smith" Tags: "Uncategorized"
Comments Send by mail Print  Save  Delicious 
Date: Saturday, 06 Mar 2010 16:06

A few days ago I received a comment from someone named Joe on my blog.  He was expressing concern over several aspects of my book Advanced MVVM, including the fact that it is written about a relatively simple game, not something more complicated.  After Joe read the book his apprehensions about it disappeared, and he kindly left me this comment:

Josh,

Ok, after reading your book, I have to say “Wow!” Not only have you managed to help me understand some of the frustrations I had with MVVM development, but your book also made some good points (which I shared with my development manager) and reinforced with real examples of issues I faced working on a project using that pattern.

I was very (pleasantly) surprised reading your take on the code-behind vs. NO code-behind mentality. I myself prefer the middle ground, but for some time was forced to do the latter. Yes, it did create several layers of very difficult to follow, understand and maintain code; from your notes and my examples, I was able to reach a compromise on how we should utilize ‘code-behind’.

Now, an interesting story –our architect chose the MVVM pattern after reading your article in MSDN in 2009. However, they chose to enforce “no code-behind” at all for the sake of testability.

The book is awesome; if you can mix MVVM with Prism and come up with a nice 300+ page book with some nice distilled information like that, I’d a) like to help write it; and b) shell out at least $50.00.

Cheers!

Joe

P.S. you’re right, there is no “Silver Bullet”; however, it would be nice to have some guide or set of documentation as to what works well when and where, especially when certain design patterns are applied to solve a problem.

It sounds like Advanced MVVM has another happy customer! :)


Author: "Josh Smith" Tags: "Announcements, mvvm"
Comments Send by mail Print  Save  Delicious 
Date: Thursday, 04 Mar 2010 21:31

I’m thrilled to announce that Tim Heuer, one of the top Silverlight community members, evangelists, and Program Managers at Microsoft, has published a review of my book Advanced MVVM.  He gave the book a very solid thumbs-up, which made my day!  If you’re interested in reading what Tim had to say, here’s the link: http://timheuer.com/blog/archive/2010/03/04/advanced-mvvm-book-for-silverlight-wpf.aspx

Thanks Tim!


Author: "Josh Smith" Tags: "Uncategorized"
Comments Send by mail Print  Save  Delicious 
Date: Thursday, 25 Feb 2010 16:32

I finally found a way to reproduce a minor issue in BubbleBurst, the application reviewed in my Advanced MVVM book.  I fixed the issue, which had to do with bursting a bubble group during an animated undo transition, and updated the source code and download files on CodePlex.  If you’re interested in seeing the fix, it’s associated with changeset 43211.

By the way, I would like to thank all of you who have bought Advanced MVVM.  I am shocked at how many copies have sold so far.  This far exceeds my expectations!


Author: "Josh Smith" Tags: "Announcements, mvvm"
Comments Send by mail Print  Save  Delicious 
Date: Thursday, 18 Feb 2010 17:00

Due to popular demand, I have made my Advanced MVVM book available for Amazon’s Kindle e-book reader.  You can get it here:

http://www.amazon.com/Advanced-MVVM-ebook/dp/B0038KX9FW

Enjoy!


Author: "Josh Smith" Tags: "Uncategorized"
Comments Send by mail Print  Save  Delicious 
Date: Monday, 15 Feb 2010 19:30

I have had quite a few people say that they want to print my Advanced MVVM e-book.  The DRM protected PDF that you get when you buy the e-book does not allow itself to be printed, as per the rules of Lulu (the online publisher).  So, to help people read the book in the format that they want, I made it possible to buy a hard copy of the book.  You can get the paperback version here.

I am also in the process of making Advanced MVVM available for the Kindle e-reader.  I will blog about it once Amazon approves my book and makes it available online.


Author: "Josh Smith" Tags: "Announcements"
Comments Send by mail Print  Save  Delicious 
Date: Monday, 15 Feb 2010 08:56

I have been working tirelessly for weeks on what I consider to be my masterpiece.  I’ve published a book called Advanced MVVM.  It is a 52 page deep dive into some complex problems and solutions in an MVVM application I wrote, called BubbleBurst.

You can buy a hard copy, or a digital copy which can be read in the free Adobe Digital Editions e-book reader.  It is also possible to read the book on your Amazon Kindle, by purchasing it here.

The full source code is available on CodePlex: http://bubbleburst.codeplex.com/

The e-book’s Table of Contents is shown below:

Chapter 1 – Introduction
  • The Demo Application
  • The Source Code
Chapter 2 – Brief Overview of WPF and MVVM
  • WPF
  • Learn More about WPF
  • MVVM
  • Learn More about MVVM
Chapter 3 – View Architecture Overview
  • BubbleBurstView
  • BubbleMatrixView
  • BubbleCanvas
  • BubbleView
  • GameOverView
  • What Should a View Do?
Chapter 4 – ViewModel Architecture Overview
  • Core ViewModel Classes
  • BubbleBurstViewModel
  • BubbleMatrixViewModel
  • Creating Bubbles with BubbleFactory
  • Finding Bubble Groups
  • A ViewModel is a Model of a View
Chapter 5 – Animated Transitions
  • What is an Animated Transition?
  • Designing for Animated Transitions
  • Animated Transitions in BubbleBurst
  • Creating Animated Transitions in the ViewModel
  • Displaying Animated Transitions in the View
Chapter 6 – Unlimited Undo with Animated Transitions
  • Responding to User Input
  • Creating Undo Tasks
  • Managing Bubble Locations
  • Benefits of a Task-based Architecture
Chapter 7 – The Game-Over Dialog
  • Opening the GameOver Dialog
  • Closing the GameOver Dialog
Chapter 8 – Recap
  • Recap
Special Thanks
About the Author

If you are interested in learning more about my e-book, please click here.

Enjoy!


Author: "Josh Smith" Tags: "Announcements, Reading Material, mvvm"
Comments Send by mail Print  Save  Delicious 
Date: Monday, 08 Feb 2010 15:36

My good friend and comrade in crime, Karl Shifflett, recently published a huge body of excellent work.  He has been working for quite some time on Ocean, a code generation system that blows my mind, and BBQ Shack, a great line-of-business WPF and Silverlight application that is built by Ocean.  His prolonged effort has resulted in some high-quality software and documentation (including videos!).

I highly suggest you set aside some time to check out what Karl has been up to.  It’s amazing work.

My hat is off to you, Karl!


Author: "Josh Smith" Tags: "Announcements, Reading Material"
Comments Send by mail Print  Save  Delicious 
Date: Friday, 08 Jan 2010 08:29

A recent post by Josh Twist shows how to support mingling code in XAML for WPF devs.  There have been several examples of putting code into XAML over the years, and they always raise the discussion of whether or not it is a good practice.  I am usually against having code in XAML because it makes it difficult to debug and maintain, but to each his/her own.  Regardless, that post got me thinking…

For a while now I’ve wondered how one might go about making it so that the little bits of code in the XAML might somehow be transplanted into the highly testable, debuggable, lovable world of the ViewModel.  Sure, you could put this type of logic into value converters, but writing a value converter that is only used once seems like a lot of extra work for little benefit.

Just for kicks, I decided to implement a class that would allow you to specify a method on your ViewModel object that contains the code that would otherwise be placed into a value converter, or in XAML.  The result is a markup extension I ever so lazily named BindingEx.  Here’s a simple usage:

Notice the last bit where the ConvertMethod property is set to AdjustTextWidth.  This is how you specify which method on the element’s VM should be invoked when the window’s width changes.  Here’s the VM class:

The TextViewModel object halves the window’s ActualWidth, and that value ends up being the width of the TextBlock.

I’m not sure that anyone should ever use this technique in a real application.  It’s probably a very stupid idea altogether, so I want to avoid any bad karma by stressing the point here:  USE AT YOUR OWN RISK!!

If you want to check out how I implemented BindingEx, click here to download the source code.  Be sure to change the file extension from .DOC to .ZIP and then decompress it.


Author: "Josh Smith" Tags: "Praxis"
Comments Send by mail Print  Save  Delicious 
Date: Wednesday, 06 Jan 2010 16:10

I recently needed to write some design-time support for a Silverlight framework.  I needed to discover a solution’s assemblies while running in Blend, and then pass those assemblies downstream for further processing.  In WPF, using the full .NET framework, that’s easy: just call AppDomain.CurrrentDomain.GetAssemblies() and then filter them based on the Location property.  In Silverlight, however, a couple of problems showed up that seemed to make this task impossible.

First, the Assembly.Location property is marked ‘Security Critical’ in Silverlight 3.  This means that if you access the property, an exception will be thrown.

Second, Silverlight 3’s AppDomain class does not have a GetAssemblies method!

It turns out that both of these problems are easy to overcome.  The key thing to know is that when Silverlight code is running in Blend, it’s actually executing against the regular .NET Framework (the same one that WPF uses).  You can access ‘Security Critical’ members and no errors occur.  That takes care of the Assembly.Location issue.  Even though the Silverlight code you write, that is intended to run in Blend, can only access the Silverlight API, you can still access the full .NET framework’s API via reflection.  This allows you to work around the second issue.  For example:

var assemblies = typeof(AppDomain)
   .GetMethod("GetAssemblies")
   .Invoke(AppDomain.CurrentDomain, null);

Remember, this hack only works when your Silverlight code is running in Blend! This will not work when running under normal circumstances, since Silverlight apps normally only have access to the Silverlight subset of the .NET Framework.

Happy coding!


Author: "Josh Smith" Tags: "Blend, Silverlight"
Comments Send by mail Print  Save  Delicious 
Date: Tuesday, 17 Nov 2009 09:42

I recently published an article on CodeProject that reviews a WPF graphing application.  It turns out that my original circular dependency detection algorithm did not detect all circles in certain scenarios.  I completely rewrote that algorithm, so that it now properly detects all circles in any object graph.

I also modified the way that the node connectors move, so that it feels more responsive and elastic.  The app is much better now, and the article has been updated to reflect these changes (including a new source code download).  If you want to check it out, here’s the link:

http://www.codeproject.com/KB/WPF/WpfGraphVisualization.aspx


Author: "Josh Smith" Tags: "Announcements"
Comments Send by mail Print  Save  Delicious 
Date: Monday, 16 Nov 2009 06:05

I spent the weekend having a blast writing a WPF app that displays an interactive object graph, and detects/highlights circular dependencies. It was so much fun, that I decided to publish an article about it on CodeProject.

Here’s a screenshot of the app:

ComplexCircularGraph

The app uses Charles Petzold’s ArrowLine element, PropertyObserver and ObservableObject from my MVVM Foundation library, DragCanvas from WPF.JoshSmith, and ContentControl3D from Thriple.

If you want to check it out, here’s the article:

http://www.codeproject.com/KB/WPF/WpfGraphVisualization.aspx

Enjoy!


Author: "Josh Smith" Tags: "3D, Announcements, Reading Material, Thr..."
Comments Send by mail Print  Save  Delicious 
Date: Saturday, 24 Oct 2009 17:55

When working on large WPF or Silverlight applications, you can end up with a lot of XAML files.  If you are using the MVVM pattern, many of those XAML files contain a View whose DataContext is expected to be set to a certain type of ViewModel object.  It can sometimes become difficult to remember which Views expects which ViewModel as their DataContext.  One very simple and lightweight way to help you and your team remember a View’s expected DataContext type is to leave an XML comment at the top of the XAML file.  This incredibly simple and obvious technique can be a HUGE timesaver later on down the road!

datacontext

I highly suggest that you get into the habit of doing this, if you haven’t done so already.  You will thank yourself many times later…


Author: "Josh Smith" Tags: "Praxis, mvvm"
Comments Send by mail Print  Save  Delicious 
Date: Wednesday, 30 Sep 2009 16:14

This morning I decided to build a little WPF dialog window that would show the visual tree of some UI, and provide visual indicators over that UI when you select one of its elements.  This was just a fun exercise.  If you want to have a serious element tree viewer, then be sure to use Snoop instead.  This quick post just shows the result of my morning fun.

Here’s the resulting dialog window in action:

snooper

Notice that a ContentPresenter is selected, which contains an image of a ninja.  In the UI being analyzed, you’ll see that the ContentPresenter is decorated with a light green box:

demowindow

The “Snooper” dialog window contains a TreeView that renders the visual tree of the other UI.  That TreeView is declared as:

treeview

It is bound to a hierarchy of VisualElement objects.  VisualElement is a class that I made to represent an element and its child elements.  The important part of that class is seen below:

visualelement

Notice that when a VisualElement is selected, it puts a SelectionAdorner into the adorner layer of its associated UIElement.  SelectionAdorner is a class I made that just renders a rectangle around some element.  It is seen below:

adorner

You can download the demo project here.  NOTE: Be sure to change the file extension from .DOC to .ZIP and then decompress.  WPF is fun!

Author: "Josh Smith" Tags: "Debugging, Praxis"
Comments Send by mail Print  Save  Delicious 
Date: Monday, 07 Sep 2009 20:59

I just published an article about a technique I use to streamline and simplify the way that ViewModels are created in an MVVM app.  I’m not saying that this is the “right” way to do things, but simply something I find useful.  Enjoy!

http://www.codeproject.com/KB/WPF/FromRussiaWithLove.aspx

Author: "Josh Smith" Tags: "Reading Material, mvvm"
Comments Send by mail Print  Save  Delicious 
Date: Saturday, 05 Sep 2009 00:02

In case you ever need to prevent the user from selecting a tab in a WPF TabControl, here’s one way to do it…

ControllingTheTabControl

The SelectedContent of the TabControl hasn’t changed at the time that the ItemsSource’s default collection view raises its CurrentChanging event.  If you decide to lock the user into the selected tab, simply set the TabControl’s SelectedIndex back to the index of the SelectedContent.  No fuss, no muss…

Author: "Josh Smith" Tags: "Praxis"
Comments Send by mail Print  Save  Delicious 
Date: Sunday, 23 Aug 2009 18:57

I set aside some time today to add some goodness, and remove some badness, from my MVVM Foundation library on CodePlex.  Special thanks go to Matt Heffron for his great work on making the Messenger class much safer and user-friendly.  Here is a listing of the changes:

  • Added safety checks and helpful error messages in Messenger for callback registration and message broadcasting. Unit tests were added to verify this behavior.
  • Ensured that Messenger notifies colleagues of a message in the order they registered for that message. Unit tests were added to verify this behavior.
  • Fixed an issue in an ObservableObject unit test where it failed in a Release build.

It’s exciting for me to see the improvements and ideas suggested by people using MVVM Foundation!  I appreciate the time people have contributed toward making the library better.  I hope there are no hard feelings when I reject a proposed feature.  :)

You can get the latest source code here: http://mvvmfoundation.codeplex.com/SourceControl/ListDownloadableCommits.aspx

Author: "Josh Smith" Tags: "mvvm"
Comments Send by mail Print  Save  Delicious 
Date: Wednesday, 15 Jul 2009 19:05

I just added a demo application to the MVVM Foundation project on CodePlex.  It is contrived, but shows how to use ViewModelBase, RelayCommand, PropertyObserver, and Messenger.  You can download the latest source code here.

Author: "Josh Smith" Tags: "Announcements, mvvm"
Comments Send by mail Print  Save  Delicious 
Next page
» You can also retrieve older items : Read
» © All content and copyrights belong to their respective authors.«
» © FeedShow - Online RSS Feeds Reader