在 XAML Silverlight 中将背景颜色应用于整个网格行

发布于 2024-09-29 05:25:30 字数 808 浏览 6 评论 0原文

我正在尝试将渐变背景应用于我创建的 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>

不幸的是,这将渐变应用于整个网格。

似乎我无法将渐变(甚至颜色)应用于网格中的单个行定义。是否可以?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧人九事 2024-10-06 05:25:30

使用 边框,然后使用 Grid.RowGrid.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>

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>
心不设防 2024-10-06 05:25:30

如果要模拟垂直顺序的两种颜色,还可以使用 Offset 属性。如果将这两个设置为相同的值,您将得到以下模拟:

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

If you want to simulate two colors in vertical order, you can also use the Offset property. If you set these two on the same value, you get this simulation:

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

You can do even more :)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文