简体   繁体   中英

How to make opacity darker in wpf

当用户单击某个按钮时,我的主窗口背景颜色为Background="#005075" ,弹出一些小窗口,然后我改变主窗口的不透明度,如Opacity="0.5" ,问题在于它使背景打火机,我该如何在WPF中暗中摆弄?

I do something similar a lot. The best way to do this is by having a couple of top-level grid's in your Window and work with those rather than the Window itself.

For example, Ill do something like this:

<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>

Opacity will not make it darker. What you can do is you can make some kind of panel which is stretched all over your main window, and has a black color and opacity of 0.2 or something like that, and mainly is hidden by default. And when you want to make the main window disabled you make that panel visible. This should solve your problem.

You can also use it as a loading panel, if you add some animation in center or something like this. So it will be over all of the content of your main window and will not allow the user to interact with your main window while it's disabled.

PS The black panel with opacity 0.2 should be positioned over all of the controls in main window

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM