15

在我的应用程序中,我希望在下面有一个透明窗口但完全不透明的子控件。但是,WPF 使所有子级透明。

请参阅下面的 XAML。正如预期的那样,网格是半透明的 50%,但其中的矩形是透明的而不是不透明的,即使考虑 opacity="1"。有什么办法可以做到这一点?

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

谢谢, 切利克

4

1 回答 1

21

您的矩形不是完全不透明的原因是因为您的容器(网格)的不透明度为 0.5,并且不透明度被继承给子对象。

相反,尝试将网格的背景画笔更改为半透明的东西,例如:

<Grid Background="#66ff0000">

这应该给你一个半透明的网格和一个完全不透明的矩形。

于 2009-06-11T18:12:25.733 回答