Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.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 对网格和don'应用不透明度;t申请其子控件_Wpf_Silverlight_Xaml - Fatal编程技术网

Wpf 对网格和don'应用不透明度;t申请其子控件

Wpf 对网格和don'应用不透明度;t申请其子控件,wpf,silverlight,xaml,Wpf,Silverlight,Xaml,我对网格应用不透明度0.75,所有具有网格的子级也采用不透明度 是否可以排除子控件而不为其应用不透明度? 谢谢大家! XAML <Grid x:Name="RootGrid" Opacity="0.75" Visibility="Visible" ClipToBounds="False" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" > <local:MarqueeVer x:Name="m

我对
网格
应用不透明度0.75,所有具有
网格
的子级也采用不透明度

是否可以排除子控件而不为其应用不透明度?

谢谢大家!

XAML

<Grid  x:Name="RootGrid" Opacity="0.75" Visibility="Visible" ClipToBounds="False" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
        <local:MarqueeVer x:Name="marquee1" Duration="30"  ClipToBounds="True"  
                          RenderTransformOrigin="0.5,0.5" Margin="0,0,0,0"
                           VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
                          Background="Transparent" Opacity="1">
            <StackPanel   Name="lstItems"   FlowDirection="LeftToRight" Orientation="Vertical"
                         VirtualizingStackPanel.IsVirtualizing="True" 
              VirtualizingStackPanel.VirtualizationMode="Recycling">
            </StackPanel>
        </local:MarqueeVer>


    </Grid>

更新

我找到了一些解决方案,但有更简单的解决方案吗

您只需为每种颜色计算正确的alpha通道


您不能使子对象比父对象更不透明,但可以使用具有不同不透明性的笔刷来实现某些叠加效果,例如

像这样:

<Window x:Class="stackoverflowviewbox.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Window.Resources>
    <SolidColorBrush Color="White" Opacity=".5" x:Key="WhiteHalfOpacityBrush"/>
</Window.Resources>
<Grid Background="Green">
    <Border BorderThickness="1" BorderBrush="Black" HorizontalAlignment="Center" VerticalAlignment="Center">
        <Grid Background="{StaticResource WhiteHalfOpacityBrush}">
            <Label>
                Hello world.Hello world.Hello world.Hello world.Hello world.Hello world.
            </Label>
        </Grid>
    </Border>
</Grid>

你好世界。你好世界。你好世界。你好世界。你好世界。你好世界。你好世界。

要实现此效果,可以将
矩形添加为
网格的子元素(但作为其他元素的同级元素),并将
背景和
不透明度
应用于
矩形。这样,不透明度的更改不会影响
栅格
的其他子级

<Grid Name="Root">
<Rectangle Name="Background" Opacity="0.75">
<Rectangle.Fill>

</Rectangle.Fill>
</Rectangle>
<Label>Hello World</Label>
</Grid>

你好,世界

我知道这可能是一个肮脏的解决方案,但它对我起到了作用。

如果你只想更改网格背景的不透明度,那么你只需要在背景图像中设置不透明度=0.75

但是我在网格上刷些什么呢?在那种情况下我能做什么


在这种情况下,设置画笔的不透明度

你能在这里发布你的xaml代码以便更好地理解吗?@EduardoBrites当然。它就在那里。请看一看。为什么要设置网格本身的不透明度?网格通常仅用于布局,不可见。如果只想更改网格背景的不透明度,则只需在背景图像中设置不透明度=0.75。在这种情况下,请在画笔中设置不透明度;)