Wpf 不透明时背景变为灰色
这是我的密码:Wpf 不透明时背景变为灰色,wpf,xaml,background,opacity,Wpf,Xaml,Background,Opacity,这是我的密码: var windows = Application.Current.Windows; var backgroundWindow = windows[windows.Count - 1]; backgroundWindow.Background = Brushes.White; backgroundWindow.Opacity = 0.5; SpecialLettersLayout layout = new SpecialLettersLayout((SmartButton)bu
var windows = Application.Current.Windows;
var backgroundWindow = windows[windows.Count - 1];
backgroundWindow.Background = Brushes.White;
backgroundWindow.Opacity = 0.5;
SpecialLettersLayout layout = new SpecialLettersLayout((SmartButton)button, KeyboardViewModel);
layout.Show();
当我打开一个新窗口时,我希望旧窗口(背景中的窗口)的不透明度为0.5。当我运行应用程序时,我得到以下结果:
如您所见,背景有点灰色。如何用白色替换灰色?您的
窗口。当您将不透明度设置为0.5
时,背景将变为灰色,因为窗口的实际背景为黑色
。您可以通过设置以下内容来验证这一点:
backgroundWindow.Background = Brushes.Transparent;
将任何容器控件的不透明度
设置为0.5
,而不是将Window.Opacity
设置为0.5
,这样您就不会使白色窗口。Background
不透明,而是使容器不透明,留下白色窗口。Background
:
<Window ...>
<Grid>
<Rectangle Fill="White" Opacity="0.5" />
<!-- Your main content -->
</Grid>
</Window>
解决我问题的方法是添加以下内容:
AllowsTransparency="True"
在我的窗口里。@Sheridan是对的,当我设置:
backgroundWindow.Background = Brushes.Transparent;
我的背景是黑色的。我不知道为什么,我从来没有将我的任何窗口的背景设置为黑色。您希望底部窗口实际上是透明的,还是您试图使其看起来对比度更低以引起对前景窗口的注意?前景窗口是弹出模式吗?如果是,您试图与屏幕重叠进行斗争如果要将ilt转换为其模板,则需要更改它,而不是更改窗口本身的不透明度。