【问题标题】:Avoid inheritance of opacity between nested Grids避免嵌套网格之间的不透明度继承
【发布时间】:2014-04-22 23:10:05
【问题描述】:

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

【问题讨论】:

    标签: c# wpf expression-blend blend


    【解决方案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>
    

    【讨论】:

      猜你喜欢
      • 2012-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-08
      • 1970-01-01
      • 2019-05-22
      相关资源
      最近更新 更多