15

In my application I'd like to have a transparent window but fully opaque children controls underneath. However, WPF makes all children transparent.

See the XAML below. The grid is semi-transparent 50% as expected but the rectangle in it is trasparent not opaque even thought opacity="1". Is there any way to achieve this?

<Window x:Class="WpfApplication10.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" AllowsTransparency="True" Height="300" ResizeMode="NoResize" Width="300" WindowStyle="None" Background="Transparent"  >

    <Border   BorderBrush="black"  BorderThickness="7" CornerRadius="10">
        <Grid Background="Red" Opacity="0.5"     >

        <Rectangle Width="100" Height="100" Fill="white" Opacity="1"/>

    </Grid>
    </Border></Window>

thanks, cellik

cellik
  • 2,116
  • 2
  • 19
  • 29

1 Answers1

21

The reason why your rectangle is not fully opaque is because your container (the grid) has an opacity of .5, and opacity gets inherited to the child objects.

Instead, try changing the Background Brush of the Grid to something semi-transparent like:

<Grid Background="#66ff0000">

This should give you a semi-transparent Grid and a fully opaque rectangle.

micahtan
  • 18,530
  • 1
  • 38
  • 33
  • The rectangle is full opaque because the color is `white`. If color changed to red for example, the red is not 100% opacity red. Do you have solution to get the 100% red rectangle? – Nam G VU Nov 04 '10 at 14:59
  • As long as the opacity on the Grid is not specified, it should also work with a 100% red rectangle. Notice that the change is to the Grid, not the Rectangle tag. – micahtan Nov 12 '10 at 00:02