Spaajanen
Spaajanen

Reputation: 383

How can I set opacity of a textbox to 1 when it is within a border with opacity 0.5?

I have the following xaml:

<Border x:Name="baseBorder" Grid.Row="0" Grid.RowSpan="200" Canvas.ZIndex="1" Opacity="0.5" Background="Gray">
    <Border x:Name="interiorBorder" Background="White" Height="200" Width="450" Opacity="1">
        <TextBlock x:Name="txtMessage" HorizontalAlignment="Center" Width="400" TextAlignment="Center" TextWrapping="Wrap" VerticalAlignment="Center" FontSize="20" FontWeight="Bold" Foreground="Black" >
    </Border>
</Border>

I want the interiorBorder to have opacity 1 while maintaining the base border's opacity 0.5.

The above xaml is not working, I'm getting 0.5 opacity in both objects.

Upvotes: 0

Views: 184

Answers (1)

Andrew
Andrew

Reputation: 905

Try making interiorBorder a sibling of baseBorder instead of a child, perhaps something like this.

<Border x:Name="baseBorder" Grid.Row="0" Grid.RowSpan="200" Canvas.ZIndex="1" Opacity="0.5" />
<Border x:Name="interiorBorder" Grid.Row="0" Grid.RowSpan="200" Canvas.ZIndex="1" Opacity="1">
    <TextBlock x:Name="txtMessage" />
</Border>

I imagine you'll also want to set Margin on interiorBorder so you'll still be able to see baseBorder.

Upvotes: 1

Related Questions