Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Make Parent Window Blurred for Better Focus on UI, in WPF

0.00/5 (No votes)
12 Apr 2011 1  
Make parent window blurred for better focus on UI, in WPF

This post is about UI experience for your application in WPF. In products, we come across situations where a user often mistakenly hits a modal form over a parent form. Either they realize once they click on the form or upon the warning message. Here, a visible inactive/shadowed background window can make user task easy, that describes some other dialog needs attention first. This concept is not new and we can find it in so many websites while showing images, etc. (For example, check the images in my blog and observe the background.)

Here in this post, we will replicate the scenario in Winform application using inbuilt effect of WPF, BlurEffect as shown in the image below:

ManasPatnaik Blog

Well, to achieve the functionality, the following piece of code is required.

/// <summary> 
/// Apply Blur Effect on the window 
/// </summary> 
/// <param name="win"></param> 
private void ApplyEffect(Window win) 
{ 
System.Windows.Media.Effects.BlurEffect objBlur = 
   new System.Windows.Media.Effects.BlurEffect(); 
objBlur.Radius = 4; 
win.Effect = objBlur; 
} 
/// <summary> 
/// Remove Blur Effects 
/// </summary> 
/// <param name="win"></param> 
private void ClearEffect(Window win) 
{ 
win.Effect = null; 
}

And check the code we need to call before showing any modal dialog.

private void btnShowDialog_Click(object sender, RoutedEventArgs e) 
{ 
WinModalDialog objModal = new WinModalDialog(); 
objModal.Owner = this; 
ApplyEffect(this); 

objModal.ShowDialog(); 

ClearEffect(this); 
}

So BlurEffect Class in System.Windows.Media.Effects is a bitmap effect that blurs the screen/control. Here in the above code, the instance of blur effect is assigned to the windows effect property. Bitmap effects are simple pixel processing operations that use bitmap sources and apply effects on it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here