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

时间:2014-04-22 23:10:06

标签: c# wpf expression-blend blend

我有一个Grid,其背景为黑色,不透明度为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警报屏幕还有另一种方法可以做到这一点吗?或者如何防止这种继承?为什么会这样?

1 个答案:

答案 0 :(得分:1)

有点凌乱,但我认为这应该有用。基本上控制是堆叠的。因此,让网格出现在第一个网格之后,它不应该影响不透明度。可能需要进行调整,但有些内容应该有效:

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