【发布时间】:2012-06-01 20:03:55
【问题描述】:
当我打开一个弹出窗口时,我正在使用以下代码在窗口上设置灰色灯光效果。它工作正常,但它基本上会重新加载所有控件或刷新主窗口。
尤其是这一行:currentWindow.Content = lightboxGrid;
Window currentWindow = Application.Current.Windows.Cast<Window>()
.SingleOrDefault(x => x.Name.Equals(MAIN_WINDOW_NAME));
Grid lightboxGrid = new Grid();
object currentWindowContent = currentWindow.Content;
currentWindow.Content = null;
lightboxGrid.Children.Add(new ContentControl()
{
Content = currentWindowContent
});
// now add the grid that will "black out" the content
Grid blackoutGrid = new Grid();
blackoutGrid.Background = new SolidColorBrush(Colors.Black);
lightboxGrid.Children.Add(blackoutGrid);
blackoutGrid.Opacity = 0.0; // start fully transparent
blackoutGrid.Loaded += blackoutGrid_Loaded;
currentWindow.Content = lightboxGrid;
this._lightboxEffectApplied = true;
在不刷新主窗口或重新加载控件的情况下,有什么选项可以产生相同的效果?
【问题讨论】:
标签: wpf popup window lightbox effect