Reputation: 1108
I have a Windows Phone 7 Application.
I have one stackpanel control that hosts some other controls. I want to set some opacity for the stackpanel and a different opacity for the contained controls. How can I do this? I tried:
<StackPanel Orientation="Vertical" Height="135" Width="450" Name="StackPanel1" Background="Gray" Opacity="0.1">
<TextBlock Name="gameStatus" TextAlignment="Center" Width="450" Margin="0, 0, 0, 0" FontSize="22" Foreground="#FFC8AB14" Text="{Binding Status}" Opacity="1"/>
<Stackpanel/>
But the contained textblock always inherits the opacity of the stackpanel...
Thanks
Upvotes: 0
Views: 1519
Reputation: 16319
As you've discovered, Opacity (like other dependency proeprties) is inherited by child elements. To work round this, simply set an alpha value in the Background color of your parent element instead of using the Opacity.
In your example, the color Gray is #808080, so to give it an opacity of 0.1, simply set: Background="#19808080"
and remove the Opacity property.
Upvotes: 6