5

我将opacity 0.75 应用于所有也具有opacityGrid的孩子。Grid

是否可以排除子控件并且不对它们应用不透明度?

谢谢!

XAML

<Grid  x:Name="RootGrid" Opacity="0.75" Visibility="Visible" ClipToBounds="False"
       VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
    <local:MarqueeVer x:Name="marquee1" Duration="30" ClipToBounds="True"
                      RenderTransformOrigin="0.5,0.5" Margin="0,0,0,0"
                      VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
                      Background="Transparent" Opacity="1">
        <StackPanel Name="lstItems" FlowDirection="LeftToRight" Orientation="Vertical"
                    VirtualizingStackPanel.IsVirtualizing="True"
                    VirtualizingStackPanel.VirtualizationMode="Recycling">
        </StackPanel>
    </local:MarqueeVer>
</Grid>

更新:

我在这里找到了一些解决方案,但有更简单的解决方案吗?

您只需要计算每种颜色的正确 Alpha 通道。

4

3 回答 3

8

如果只想改变网格背景的不透明度,那么只需要在背景图片中设置 opacity=0.75。

但是我在网格上应用了一些画笔?在这种情况下我能做什么?

在这种情况下,在画笔中设置不透明度

于 2012-05-17T13:56:37.223 回答
2

为了达到这种效果,您可以添加 aRectangle作为 的子Grid元素(但作为其他元素的兄弟)并将BackgroundandOpacity应用于Rectangle. 这样,不透明度的变化不会影响Grid.

<Grid Name="Root">
<Rectangle Name="Background" Opacity="0.75">
<Rectangle.Fill>

</Rectangle.Fill>
</Rectangle>
<Label>Hello World</Label>
</Grid>

我知道这可能是一个肮脏的解决方案,但它对我有用。

于 2012-05-17T13:49:51.390 回答
0

你不能让孩子比父母更不透明,但你可以使用不同不透明度的画笔来实现一些叠加效果。

像这样:

<Window x:Class="stackoverflowviewbox.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Window.Resources>
    <SolidColorBrush Color="White" Opacity=".5" x:Key="WhiteHalfOpacityBrush"/>
</Window.Resources>
<Grid Background="Green">
    <Border BorderThickness="1" BorderBrush="Black" HorizontalAlignment="Center" VerticalAlignment="Center">
        <Grid Background="{StaticResource WhiteHalfOpacityBrush}">
            <Label>
                Hello world.Hello world.Hello world.Hello world.Hello world.Hello world.
            </Label>
        </Grid>
    </Border>
</Grid>

于 2012-05-17T13:41:39.367 回答