Welcome to irritatedVowel.com Sign in | Help

POKE 53280,0: Pete Brown's Blog

Silverlight, WPF, Windows Client Development, Woodworking, .NET Programming, CNC, Nature, and other topics.

Subscribe

Subscribe to my feed
Add to Technorati Favorites

My Book

Order my upcoming book, Silverlight in Action, covering Silverlight 4, ViewModel/MVVM, WCF RIA Services, MEF and more

About Pete Brown

Pete Brown is a Microsoft Developer Division Community Program Manager, focusing on Windows Client Development as well as a former Microsoft Silverlight MVP and INETA Speaker. Pete writes on a number of topics including Silverlight, WPF, .NET, woodworking and working as a consultant in the DC area. read more

Community Events


who's online

AddThis Social Bookmark Button

Using Blur to make Dialogs Pop in Silverlight 3

When an application needs to display a dialog, there needs to be something to make the user immediately focus on that dialog, even when there are lots of other elements on the screen

Most AJAX applications dim the screen behind a dialog by using a semi-transparent overlay. That certainly works well, but another effect to consider is a blur effect.

Here’s the dim effect

image

And here’s what a blur effect could look like, with the dark overlay retained. To remove the overlay, you’ll need to retemplate the control.

image

With more fields on-screen, the effect is certainly more compelling:

image

The code to create the blur is pretty simple. In this case, I put it right in the Application_UnhandledException function that displays the error dialog. You may wish to add it to a standard dialog base class or a helper library.

e.Handled = true;
ChildWindow ErrorWin = new ErrorWindow(e.ExceptionObject);
ErrorWin = new ErrorWindow(e.ExceptionObject);

ErrorWin.Closed += (s, args) => 
    { Application.Current.RootVisual.Effect = null; };

BlurEffect blur = new BlurEffect();
blur.Radius = 10;

Application.Current.RootVisual.Effect = blur;

ErrorWin.Show();

Note that I use a lambda expression in-line to avoid creating an event handler for the closing event. Technically you’d probably want to add some code to also remove the event handler.

Simply, the code above adds a blur effect to the application’s RootVisual just before the dialog is displayed. When the dialog closes, it removes the effect.

Another interesting approach would be for the Closed handler to do a quick animation of the blur radius from 10 to 0 and then turn off the effect when the storyboard completes. The result would be a nice re-focusing of the content in the application. I’d also recommend re-templating the child window to remove the overlay if you plan to do anything creative with the blur.

  Add to Technorati Favorites
Posted: Monday, March 23, 2009 10:27 PM by Pete.Brown
Filed under: ,

Comments

Mark said:

Nice effect, compelling and looks good too. Nice use of a 2D depth cue to produce that pop-out effect and it also prevents the background text from competing for the user's attention, cool. It should probably still be used with some discretion because there are often times when the user will benefit from the context provided by that background information while they read the dialog.
# March 24, 2009 11:38 AM

DotNetShoutout said:

Thank you for submitting this cool story - Trackback from DotNetShoutout
# March 24, 2009 6:09 PM

Daniel Vogt said:

Hi. It would be nice if there were a online viewable demo or complete source code as a VS2008-solution. Further, I think a Storyboard which smoothly blends this effect in maybe 0.5 seconds is a nice addition.
# March 25, 2009 5:35 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Enter the text you see in the image:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS