0

我的项目要求是,网格背景中的图像,并希望在顶部和底部应用黑色渐变。请帮助我如何实现这一目标。

我的 XAML 如下:

<Grid Grid.Row="0" HorizontalAlignment="Stretch" Height="190" VerticalAlignment="Stretch" ShowGridLines="False" Margin="0,2,0,0">
     <Grid.Background>
             <ImageBrush Stretch="UniformToFill" Opacity="0.6">
                   <ImageBrush.ImageSource>
                         <BitmapImage CreateOptions="BackgroundCreation" UriSource="{Binding Banner}"></BitmapImage>
                    </ImageBrush.ImageSource>
              </ImageBrush>
     </Grid.Background>
     .....
</Grid
4

2 回答 2

0
<Grid.Background>
        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="Black" Offset="0"/>
            <GradientStop Color="Gray" Offset="1"/>
        </LinearGradientBrush>
    </Grid.Background>

将颜色值更改为您想要的值。这应该够了吧。

于 2012-12-17T04:55:12.743 回答
0

在这个里面创建另一个网格。在这个新网格中,创建三行。第一行和最后一行应该有一个带渐变的矩形。像这样的东西:

<Grid Grid.Row="0" HorizontalAlignment="Stretch" Height="190" VerticalAlignment="Stretch" ShowGridLines="False" Margin="0,2,0,0">
     <Grid.Background>
         <ImageBrush Stretch="UniformToFill" Opacity="0.6">
               <ImageBrush.ImageSource>
                     <BitmapImage CreateOptions="BackgroundCreation" UriSource="{Binding Banner}"></BitmapImage>
                </ImageBrush.ImageSource>
          </ImageBrush>
      </Grid.Background>
      <Grid Grid.ColumnSpan="..." Grid.RowSpan="...">
           <Grid.RowDefinitions>
                <RowDefinition Height="25"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="25"/>
           </Grid.RowDefinitions>
           <Rectangle Grid.Row="0">
                <Rectangle.Fill>
                     ...
                </Rectangle.Fill>
           </Rectangle>
           <Rectangle Grid.Row="2">
                <Rectangle.Fill>
                     ...
                </Rectangle.Fill>
           </Rectangle>
      </Grid>
</Grid
于 2012-12-17T09:02:09.060 回答