How do I darken all screen area and glow my opened window in WPF?
Asked Answered
S

4

9

In WPF, how do I darken all screen area when opening a new window?

Also after the window is closed, how do I revert the temporary effect?

Sahara answered 23/12, 2010 at 15:55 Comment(1)
You can check this link: #5826027Sorcerer
K
14

You may create a background transparent window like this:

var darkwindow = new Window() {
                            Background = Brushes.Black,
                            Opacity = 0.4,
                            AllowsTransparency = true,
                            WindowStyle = WindowStyle.None,
                            WindowState = WindowState.Maximized,
                            Topmost = true
                        };
darkwindow.Show();
MessageBox.Show("Hello");
darkwindow.Close();

and replace MessageBox.Show("Hello"); with mywindow.ShowModal();. Possibly, you'll need to make mywindow always on top.

Edit

Don't use darkwindow.Hide() instead of Close().

Kalynkam answered 24/12, 2010 at 15:44 Comment(1)
thanks Mykola Bogdiuk. i create a dark and transparent border over the window and then i showed new windowSahara
S
28

Here is my version, if you want gray out and blur the parent window:

private void btnOpenSettings_Click(object sender, RoutedEventArgs e)
    {
        // settings for the parent window
        // set the transparency to the half
        this.Opacity = 0.5;
        // blur the whole window
        this.Effect = new BlurEffect();

        // Set the options for the settings (child) window
        SettingsForm wdwSettings = new SettingsForm() 
        { 
            Owner = this,
            ShowInTaskbar = false,
            Topmost = true
        };

        // Open the child window
        wdwSettings.ShowDialog();

        //restore Opacity and remove blur after closing the child window
        this.Opacity = 1;
        this.Effect = null;
    }
Surefooted answered 3/2, 2013 at 12:59 Comment(2)
it works great, but how can i go back to the original state once the ShowDialog() closes ?Opia
Never mind :) this.Effect = null; sets it back to normalOpia
K
14

You may create a background transparent window like this:

var darkwindow = new Window() {
                            Background = Brushes.Black,
                            Opacity = 0.4,
                            AllowsTransparency = true,
                            WindowStyle = WindowStyle.None,
                            WindowState = WindowState.Maximized,
                            Topmost = true
                        };
darkwindow.Show();
MessageBox.Show("Hello");
darkwindow.Close();

and replace MessageBox.Show("Hello"); with mywindow.ShowModal();. Possibly, you'll need to make mywindow always on top.

Edit

Don't use darkwindow.Hide() instead of Close().

Kalynkam answered 24/12, 2010 at 15:44 Comment(1)
thanks Mykola Bogdiuk. i create a dark and transparent border over the window and then i showed new windowSahara
V
9

Decrease the opacity of the current window,

For ex:

{
    this.Opacity = 0.5;//Decrease opacity
    MessageBox.Show("Ur Window Darken");
    this.Opacity = 100;//Reset the opacity
}
Vlissingen answered 14/6, 2017 at 9:44 Comment(1)
Simple solutionToulon
A
0

easiest way:use XAML pop-up as described below

<Popup x:Name="pop" IsOpen="False" >

</Popup> 

For more details visit below link. http://www.c-sharpcorner.com/UploadFile/mahesh/using-xaml-popup-in-wpf/

After this to blur the main grid on eventhandler for the event which shows the pop-up,set the opacity as shown in below C# code

if (pop.IsOpen == false)    
{    
pop.IsOpen = true;    
grdMain.Opacity = 0.4;    
}    
else    
{    
pop.isopen=false;    
}    
Abbotsen answered 13/3, 2015 at 14:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.