我的主窗口背景颜色是Background="#005075"
当用户点击某个按钮时弹出一些小窗口,然后我像Opacity="0.5"
一样改变主窗口的不透明度,问题是它使背景更亮,我如何在wpf中使暗色?
发布于 2019-01-10 16:53:38
不透明不会使其变暗。你能做的就是做一些面板,它在你的主窗口上伸展开,黑色,不透明度0.2左右,默认情况下主要是隐藏的。当您想要禁用主窗口时,您可以使该面板可见。这应该可以解决您的问题。
你也可以使用它作为一个加载面板,如果你在中心添加一些动画或类似的东西。因此,它将覆盖主窗口的所有内容,并且不允许用户在主窗口被禁用时与其交互。
附注:不透明度为0.2的黑色面板应位于主窗口中所有控件的上方
发布于 2019-01-10 17:03:24
我经常做类似的事情。要做到这一点,最好的方法是在您的窗口中设置几个顶级网格,并使用这些网格而不是窗口本身。
例如,我会这样做:
<Window x:Class="WpfApp9.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:WpfApp9"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<!-- Background grid with 100% opacity -->
<Grid Background="#005075"/>
<!-- main grid, which sits on top of the background grid -->
<Grid x:Name="MainGrid" Background="Transparent" Opacity="0.5">
<!-- Windows controls go here -->
</Grid>
</Grid>
</Window>
https://stackoverflow.com/questions/54124868
复制相似问题