Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF中透明图形中的不透明元素_Wpf_Transparency - Fatal编程技术网

WPF中透明图形中的不透明元素

WPF中透明图形中的不透明元素,wpf,transparency,Wpf,Transparency,在我的应用程序中,我希望在下面有一个透明的窗口,但完全不透明的子控件。但是,WPF使所有子级都透明 请参见下面的XAML。网格是半透明的,按预期为50%,但其中的矩形是透明的,即使不透明度为=“1”,也不不透明。有没有办法做到这一点 <Window x:Class="WpfApplication10.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schem

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

请参见下面的XAML。网格是半透明的,按预期为50%,但其中的矩形是透明的,即使不透明度为=“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>

谢谢,
cellik

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

相反,请尝试将栅格的背景笔刷更改为半透明,如:

<Grid Background="#66ff0000">


这将为您提供一个半透明网格和一个完全不透明的矩形。

矩形是完全不透明的,因为颜色是白色。例如,如果颜色更改为红色,则红色不是100%不透明度红色。你有办法得到100%红色的矩形吗?只要没有指定网格上的不透明度,它也应该适用于100%红色的矩形。请注意,所做的更改是网格,而不是矩形标记。