如何在WPF中使所有屏幕区域变暗并使我打开的窗口发光?

ham*_* aj 9 wpf window effects

在WPF中,如何在打开新窗口时使所有屏幕区域变暗?

窗口关闭后,如何恢复临时效果?

Smo*_*lla 22

这是我的版本,如果你想要灰色并模糊父窗口:

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;
    }
Run Code Online (Sandbox Code Playgroud)


Myk*_*iuk 14

您可以创建一个这样的背景透明窗口:

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();
Run Code Online (Sandbox Code Playgroud)

并替换MessageBox.Show("Hello");mywindow.ShowModal();.可能,你需要mywindow始终保持领先.

编辑

不要使用darkwindow.Hide()而不是Close().


小智 7

降低当前窗口的不透明度,

例如:

{
    this.Opacity = 0.5;//Decrease opacity
    MessageBox.Show("Ur Window Darken");
    this.Opacity = 100;//Reset the opacity
}
Run Code Online (Sandbox Code Playgroud)