WPF DataGrid RowDetailsTemplate更改背景颜色(不是行或列)

时间:2014-07-31 10:25:39

标签: c# wpf datagrid

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

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

所以我正在寻找像

这样的东西
   <DataGrid.RowDetailsTemplate>
        <DataTemplate>
             <Style TargetType="{x:Type DataGridRow}"...
              ...

然而,环顾四周我只能看到DataGridRow,列等,但是想要为这个网格的周围区域设置风格,这可能是风格吗?

干杯

3 个答案:

答案 0 :(得分:0)

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

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

...

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

答案 1 :(得分:0)

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

enter image description here

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

答案 2 :(得分:0)

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

        <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>
相关问题