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

问题描述 投票:9回答:4

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

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

wpf window effects
4个回答
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();

并用MessageBox.Show("Hello");取代mywindow.ShowModal();。可能,你需要让mywindow始终排在最前面。

编辑

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


19
投票

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

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;
    }

6
投票

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

例如:

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

0
投票

最简单的方法:使用XAML弹出窗口,如下所述

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

</Popup> 

有关详细信息,请访问以下链接http://www.c-sharpcorner.com/UploadFile/mahesh/using-xaml-popup-in-wpf/

在此之后模糊显示弹出窗口的事件的eventhandler上的主网格,设置不透明度,如下面的C#代码所示

if (pop.IsOpen == false)    
{    
pop.IsOpen = true;    
grdMain.Opacity = 0.4;    
}    
else    
{    
pop.isopen=false;    
}    
© www.soinside.com 2019 - 2024. All rights reserved.