我正在尝试在我的应用程序中模拟一个“模态”类型的事件,该事件将提供透明背景“变暗”的感觉,以及一个包含内容的表单。
我遇到的问题是我在覆盖画布上设置不透明度,它在子窗体上继承。
这显示在下面的屏幕截图中。您仍然可以看到背景项目的角落。
我正在使用的代码如下:
protected void Draw(DrawingContext drawingContext)
{
//Crate Overlay Canvas
Canvas canvas = new Canvas();
canvas.Width = ((Canvas)this.AdornedElement).ActualWidth;
canvas.Height = ((Canvas)this.AdornedElement).ActualHeight;
canvas.Opacity = .4;
canvas.Background = new SolidColorBrush(Colors.Black);
//Create Form Panel
StackPanel panel = new StackPanel();
panel.Background = new SolidColorBrush(Colors.White);
panel.Width = 400;
panel.Height = 200;
panel.Opacity = 1; //Just to make sure
Button button = new Button();
button.Content = "Test Button";
button.Height = 30;
panel.Children.Add(button);
Canvas.SetLeft(panel, canvas.Width/2);
Canvas.SetTop(panel, canvas.Height/2);
canvas.Children.Add(panel);
Content = canvas;
}