Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply opacity for Grid and don't apply for its children Controls

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.

like image 560
Friend Avatar asked May 17 '12 13:05

Friend


2 Answers

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

like image 170
Eduardo Brites Avatar answered Nov 05 '22 16:11

Eduardo Brites


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.

like image 2
Jesús Otero Avatar answered Nov 05 '22 15:11

Jesús Otero