我正在尝试将渐变背景应用于我创建的XAML Silverlight网格中的一行。
我可以毫无困难地做这样的事情:
<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>
不幸的是,这会将渐变应用于整个网格。
似乎我无法将渐变(甚至颜色)应用于网格中的单个行定义。有可能吗?
谢谢!
答案 0 :(得分:47)
使用Border
,然后使用Grid.Row
和Grid.ColumnSpan
将其放在您想要的Grid
的特定行中。
<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>
答案 1 :(得分:0)
如果要以垂直顺序模拟两种颜色,还可以使用“偏移”属性。如果将这两个设置为相同的值,则可以进行此模拟:
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Green" Offset="0.366" />
<GradientStop Color="Red" Offset="0.366" />
</LinearGradientBrush>
</Border.Background>
你可以做更多:)
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Green" Offset="0.3" />
<GradientStop Color="Red" Offset="0.3" />
<GradientStop Color="Red" Offset="0.7" />
<GradientStop Color="Yellow" Offset="0.7" />
<GradientStop Color="Yellow" Offset="0.9" />
<GradientStop Color="Blue" Offset="0.9" />
</LinearGradientBrush>
</Border.Background>