Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applying a background color to an entire Grid row in XAML Silverlight

I'm trying to apply a gradient background to just one row in a XAML Silverlight grid that I've created.

I can do something like this without any trouble:

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

    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition/>
    </Grid.RowDefinitions>

    <!-- components and various stuffs -->
</Grid>

Unfortunately this applies the gradient to the entire grid.

It seems as though I can't apply a gradient (or even a color) to an individual row definition in the grid. Is it possible?

Thanks!

like image 850
Mike Cialowicz Avatar asked Oct 27 '10 19:10

Mike Cialowicz


1 Answers

Use a Border, and then use Grid.Row and Grid.ColumnSpan to put it in the specific row of the Grid that you want.

<Grid>
   <Grid.ColumnDefinitions>
       <ColumnDefinition/>
       <ColumnDefinition/>
   </Grid.ColumnDefinitions>
   <Grid.RowDefinitions>
       <RowDefinition/>
       <RowDefinition/>
   </Grid.RowDefinitions>

   <Border Grid.Row="1" Grid.ColumnSpan="2">
      <Border.Background>
         <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="Black" Offset="0" />
            <GradientStop Color="White" Offset="1" />
         </LinearGradientBrush>
      </Border.Background>
   </Border>

   <!-- other controls in the grid -->
</Grid>
like image 121
Donut Avatar answered Nov 20 '22 21:11

Donut