2012-12-16 77 views
0

我的項目需求類似於網格背景中的圖像,並且想要以黑色在頂部和底部應用漸變。請幫助我,我該如何實現這一目標。Silverlight Grid具有漸變效果的背景圖像

我的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

在這一個裏面創建另一個網格。在這個新的網格中,創建三行。第一行和最後一行應該有一個帶有漸變的矩形。類似這樣的:

<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 
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> 

變化的顏色,你的願望是什麼價值。這應該夠了吧。