【问题标题】:WPF DataGrid RowDetailsTemplate change the background color (Not rows or columns)WPF DataGrid RowDetailsTemplate 更改背景颜色(不是行或列)
【发布时间】:2014-07-31 10:25:38
【问题描述】:

我有一个绑定并运行良好的 RowDetailsTemplate。

但现在我想在第二个 DataGrid 的背景中设置样式,以更清楚地向用户显示他们在下一个波段中。

所以我正在寻找类似的东西

   <DataGrid.RowDetailsTemplate>
        <DataTemplate>
             <Style TargetType="{x:Type DataGridRow}"...
              ...

但是,环顾四周,我只能看到 DataGridRow、columns 等,但是要设置此网格周围区域的样式,是否可以设置样式?

干杯

【问题讨论】:

  • 不知道为什么这被否决了,我知道你的意思。我在以前的项目中有类似的东西 - 我去检查时 1 分钟

标签: c# wpf datagrid


【解决方案1】:

如果您想更改 RowDetails 的背景,请执行以下操作:

    <Window.Resources> 
    <DataTemplate x:Key="RowButtons">
                <Grid Background="Aqua">
                   ...
                </Grid>
            </DataTemplate>
    </Window.Resources> 

...

<DataGrid SelectionMode="Single"  ItemsSource="{Binding CrawlsCollection}"  RowDetailsTemplate="{StaticResource RowButtons}">...</DataGrid>
...

【讨论】:

    【解决方案2】:

    刚刚检查过,我有一个嵌套网格,但使用了彩色标题栏来更好地区分父网格和嵌套网格。

    或者你可以通过代码来实现?检测一行何时具有行详细信息,然后将其设置为背景。 e.Row.Foreground = New SolidColorBrush With {.Color = Colors.Black}

    【讨论】:

      【解决方案3】:

      如果您将模板放入容器中并设置该容器背景,则会填充模板控件后面的区域。请注意使用填充为控件周围的背景提供空间。

              <DataGrid.RowDetailsTemplate>
                  <DataTemplate>
                      <Border Background="DarkGray" Padding="20,4,4,4">
                      <DataGrid ItemsSource="{Binding MyDetailsList}" AutoGenerateColumns="False"  Background="Transparent">
                          <DataGrid.Columns>
                              <DataGridTextColumn Header="Col 1" Binding="{Binding Field1}" />
                              <DataGridTextColumn Header="Col 2" Binding="{Binding Field2, StringFormat=0.000}"  />
                              <DataGridTextColumn Header="Col 3" /> 
                              <DataGridTextColumn Header="Col 4" Binding="{Binding Field3}" />
                          </DataGrid.Columns>
                      </DataGrid>
                      </Border>
                  </DataTemplate>
              </DataGrid.RowDetailsTemplate>
      

      【讨论】:

        猜你喜欢
        • 2013-03-16
        • 2015-08-22
        • 1970-01-01
        • 2020-06-02
        • 2018-09-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-01
        相关资源
        最近更新 更多