我的项目要求就像网格背景中的图像,并希望在顶部和底部应用渐变黑色。请帮助我如何实现这一目标。
我的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
答案 0 :(得分: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>
将颜色的值更改为您想要的颜色。这应该可以解决问题。
答案 1 :(得分: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