5

I apply opacity 0.75 for the Grid and all children which has Grid also take the opacity.

Is it possible to exclude child Controls and don't apply opacity for them?

Thank you!

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>

UPDATE:

I found some solution here but is any simpler solution?

You just have to calculate the right alpha channel for each color.

Nishan
  • 3,644
  • 1
  • 32
  • 41
NoWar
  • 36,338
  • 80
  • 323
  • 498

3 Answers3

8

If you only want to change the opacity of the grid's background, then you need to set the opacity=0.75 only in the background image.

But what I Apply some Brush to the Grid? WHat I can do in thhat case?

In the that case set the opacity in the brush

Eduardo Brites
  • 4,597
  • 5
  • 36
  • 51
2

To achieve this effect, you can add a Rectangle as a child of the Grid (but as a sibling to the other elements) and apply the Background and Opacity to the Rectangle. This way, the change of opacity doesn't affect the other children of the Grid.

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

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

I know this is probably a dirty solution, but it did the trick for me.

Jesús Otero
  • 197
  • 4
  • 17
0

You can't make child more opaque than parent, but you can use brushes with different opacity, to achieve some overlay effects for example.

Like this:

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

trimeyko
  • 129
  • 6