LinearGradientBrush to Transparency显示白色背景

问题描述 投票:1回答:1

我有background颜色的#424242ListBox和一些内容..

enter image description here

我希望在控件之上有一个来自#424242的LinearGradientBrush,直到Transparent。问题是,我得到一个白色背景颜色:

enter image description here

如果我用Transparent替换#00000000我有一个深色/黑色:

enter image description here

XAML Code

<Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="136*"/>
            <RowDefinition Height="203*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <StackPanel Orientation="Vertical" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Center">
            <TextBlock Text="Transparent to #424242"></TextBlock>
            <TextBlock Text="Transparent to #424242"></TextBlock>
            <TextBlock Text="Transparent to #424242"></TextBlock>
            <TextBlock Text="Transparent to #424242"></TextBlock>
            <TextBlock Text="Transparent to #424242"></TextBlock>
            <TextBlock Text="Transparent to #424242"></TextBlock>
            <TextBlock Text="Transparent to #424242"></TextBlock>
            <TextBlock Text="Transparent to #424242"></TextBlock>
            <TextBlock Text="Transparent to #424242"></TextBlock>
            <TextBlock Text="Transparent to #424242"></TextBlock>
            <TextBlock Text="Transparent to #424242"></TextBlock>
            <TextBlock Text="Transparent to #424242"></TextBlock>
            <TextBlock Text="Transparent to #424242"></TextBlock>
            <TextBlock Text="Transparent to #424242"></TextBlock>
            <TextBlock Text="Transparent to #424242"></TextBlock>
        </StackPanel>
        <Rectangle Grid.Column="0" Grid.Row="0">
            <Rectangle.Fill>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Transparent" Offset="0"/>
                    <GradientStop Color="#424242" Offset="1"/>
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>

        <StackPanel Orientation="Vertical" Grid.Column="1" Grid.Row="0" HorizontalAlignment="Center">
            <TextBlock Text="#00000000 to #424242"></TextBlock>
            <TextBlock Text="#00000000 to #424242"></TextBlock>
            <TextBlock Text="#00000000 to #424242"></TextBlock>
            <TextBlock Text="#00000000 to #424242"></TextBlock>
            <TextBlock Text="#00000000 to #424242"></TextBlock>
            <TextBlock Text="#00000000 to #424242"></TextBlock>
            <TextBlock Text="#00000000 to #424242"></TextBlock>
            <TextBlock Text="#00000000 to #424242"></TextBlock>
            <TextBlock Text="#00000000 to #424242"></TextBlock>
            <TextBlock Text="#00000000 to #424242"></TextBlock>
            <TextBlock Text="#00000000 to #424242"></TextBlock>
            <TextBlock Text="#00000000 to #424242"></TextBlock>
            <TextBlock Text="#00000000 to #424242"></TextBlock>
            <TextBlock Text="#00000000 to #424242"></TextBlock>
            <TextBlock Text="#00000000 to #424242"></TextBlock>
        </StackPanel>
        <Rectangle Grid.Column="1" Grid.Row="0">
            <Rectangle.Fill>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#00000000" Offset="0"/>
                    <GradientStop Color="#424242" Offset="1"/>
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>

        <StackPanel Orientation="Vertical" Grid.Column="2" Grid.Row="0" HorizontalAlignment="Center">
            <TextBlock Text="Hello World"></TextBlock>
            <TextBlock Text="Hello World"></TextBlock>
            <TextBlock Text="Hello World"></TextBlock>
            <TextBlock Text="Hello World"></TextBlock>
            <TextBlock Text="Hello World"></TextBlock>
            <TextBlock Text="Hello World"></TextBlock>
            <TextBlock Text="Hello World"></TextBlock>
            <TextBlock Text="Hello World"></TextBlock>
            <TextBlock Text="Hello World"></TextBlock>
            <TextBlock Text="Hello World"></TextBlock>
            <TextBlock Text="Hello World"></TextBlock>
            <TextBlock Text="Hello World"></TextBlock>
            <TextBlock Text="Hello World"></TextBlock>
            <TextBlock Text="Hello World"></TextBlock>
            <TextBlock Text="Hello World"></TextBlock>
        </StackPanel>
        <Rectangle Grid.Column="2" Grid.Row="0" Opacity="0">
            <Rectangle.Fill>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#424242" Offset="0"/>
                    <GradientStop Color="#424242" Offset="1"/>
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
    </Grid>
</Grid>

enter image description here

c# wpf expression-blend
1个回答
0
投票

我有答案:只需使用与Alpha 0%相同的颜色

<Rectangle.Fill>
    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
        <GradientStop Color="#FF424242" Offset="1"/>
        <GradientStop Color="#00424242"/>
    </LinearGradientBrush>
</Rectangle.Fill>
© www.soinside.com 2019 - 2024. All rights reserved.