Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 211
hamed aj Avatar asked Dec 23 '10 15:12

hamed aj


2 Answers

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;
    }
like image 60
Smolla Avatar answered Sep 20 '22 17:09

Smolla


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().

like image 36
Mykola Bogdiuk Avatar answered Sep 23 '22 17:09

Mykola Bogdiuk