【问题标题】:wpf Popup Lightbox effect on window窗口上的 wpf 弹出灯箱效果
【发布时间】: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


    【解决方案1】:

    如果您的主窗口有一个 Grid 作为其布局根(即使所有内容都在第一个单元格中),那么您可以将此 blackoutGrid 作为子级添加到该网格中,它将显示在其他元素上方而不会弄乱原始的可视化树结构。

    在这种情况下,您的窗口的内容将是一个网格,您可以将 blackoutGrid 添加到该网格,并在完成后将其删除。

    你写这篇文章的方式似乎有点违背面向对象的做法。从技术上讲,它应该是您的主窗口能够显示灯箱效果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多