Click here to Skip to main content
15,886,795 members
Articles / Desktop Programming / WPF

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

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
12 Apr 2011CPOL 16.5K   6  
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.

C#
/// <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.

C#
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Microsoft
India India
Nothing special .. I like challenges and love my critics.

Microsoft | Bangalore | India

Blog : http://manaspatnaik.com/blog

Twitter@manas_patnaik

Comments and Discussions

 
-- There are no messages in this forum --