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

发布于 2024-10-09 02:46:18 字数 61 浏览 5 评论 0原文

在 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

铜锣湾横着走 2024-10-16 02:46:18

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

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

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;
    }
权谋诡计 2024-10-16 02:46:18

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

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

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

一身软味 2024-10-16 02:46:18

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

例如:

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

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
}
这样的小城市 2024-10-16 02:46:18

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

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

</Popup> 

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

之后,为了模糊显示弹出窗口的事件的事件处理程序上的主网格,设置不透明度,如下面的 C# 代码所示

if (pop.IsOpen == false)    
{    
pop.IsOpen = true;    
grdMain.Opacity = 0.4;    
}    
else    
{    
pop.isopen=false;    
}    

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;    
}    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文