避免在嵌套栅格之间继承不透明度

本文关键字:之间 继承 不透明度 嵌套 | 更新日期: 2023-09-27 17:59:42

我有一个背景为黑色、不透明度为0.5的网格,还有另一个不透明度为1、背景为白色的网格。但内部网格仍然显示其不透明度为0.5

    <Grid Grid.ColumnSpan="2" Grid.RowSpan="2" Background="Black" Opacity="0.5" Visibility="{Binding Alertar, Converter={cnv:boolToVisibilityConverter}}">
        <Grid.RowDefinitions>
            <RowDefinition Height="2*"></RowDefinition>
            <RowDefinition Height="5*"></RowDefinition>
            <RowDefinition Height="2*"></RowDefinition>
        </Grid.RowDefinitions>
        <Grid Grid.Row="1" Background="Black" Opacity="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="3*"/>
                <ColumnDefinition Width="7*"/>
                <ColumnDefinition Width="3*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="10*"/>
                <RowDefinition Height="1.5*"/>
            </Grid.RowDefinitions>
            <Rectangle Grid.ColumnSpan="3" Grid.RowSpan="2" Fill="Black" Opacity="1"/>
            <TextBlock Grid.Column="1" Margin="0,15,0,0" Text="{Binding ReporteInconsistencias}" />
            <Button Grid.Column="1" Grid.Row="1" Content="Aceptar" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10"/>
        </Grid>
    </Grid>

我正在尝试模拟win8警报屏幕,还有其他方法可以做到这一点吗?或者如何防止这种继承?为什么会发生这种情况?

避免在嵌套栅格之间继承不透明度

有点乱,但我认为这应该可行。基本上,控件是堆叠的。因此,如果网格位于第一个网格之后,就不会影响不透明度。可能需要调整,但应该可以这样做:

  <Grid Grid.ColumnSpan="2" Grid.RowSpan="2" Visibility="{Binding Alertar, Converter={cnv:boolToVisibilityConverter}}">
    <Grid.RowDefinitions>
        <RowDefinition Height="2*"></RowDefinition>
        <RowDefinition Height="5*"></RowDefinition>
        <RowDefinition Height="2*"></RowDefinition>
    </Grid.RowDefinitions>
    <Grid Grid.RowSpan="3" Background="Black" Opacity="0.5" />        
    <Grid Grid.Row="1" Background="Black" Opacity="1">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="3*"/>
            <ColumnDefinition Width="7*"/>
            <ColumnDefinition Width="3*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="10*"/>
            <RowDefinition Height="1.5*"/>
        </Grid.RowDefinitions>
        <Rectangle Grid.ColumnSpan="3" Grid.RowSpan="2" Fill="Black" Opacity="1"/>
        <TextBlock Grid.Column="1" Margin="0,15,0,0" Text="{Binding ReporteInconsistencias}" />
        <Button Grid.Column="1" Grid.Row="1" Content="Aceptar" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10"/>
    </Grid>
</Grid>