我想在我的WPF应用程序上实现这个功能。我希望在弹出窗口(子窗口)出现的整个屏幕(父窗口)上有一个变暗的覆盖/背景,这样弹出窗口(子窗口)就会像下面的图像一样具有更高的可见性。它是一个浏览器弹出窗口。然后,当关闭弹出窗口(子窗口)时,移除变暗的覆盖/背景。

发布于 2017-10-05 01:25:06
在启动对话框之前,请修改父窗口的Effect属性:
parentWindow.Effect = new BlurEffect();当对话框关闭时:
parentWindow.Effect = null;为了给覆盖图添加颜色,你可以在层中工作(为了简单起见,我将使用代码隐藏方法;如果你有时间,可以使用MVVM/behavior ):
XAML:
<Window x:Class="WpfApp3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp3"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid x:Name="Grid">
<Grid Margin="20">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Label>Label</Label>
<TextBox Grid.Row="1"></TextBox>
<Button Click="ButtonBase_OnClick">Click</Button>
</Grid>
<Border x:Name="Splash" Grid.RowSpan="4" Opacity=".2" Visibility="Collapsed" Background="Black">
</Border>
</Grid>
</Window>代码:
using System.Windows;
using System.Windows.Media.Effects;
namespace WpfApp3
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
Grid.Effect = new BlurEffect();
Splash.Visibility = Visibility.Visible;
var dlg = new Window();
dlg.ShowDialog();
Splash.Visibility = Visibility.Collapsed;
Grid.Effect = null;
}
}
}https://stackoverflow.com/questions/46568810
复制相似问题