簡體   English   中英

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

[英]WPF DataGrid RowDetailsTemplate change the background color (Not rows or columns)

我有一個RowDetailsTemplate可以綁定並很好地工作。

但是,現在我想在第二個DataGrid的背景中設置樣式,以便向用戶更清楚地顯示它們在下一個波段中。

所以我正在尋找類似的東西

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

但是,環顧四周,我只能看到DataGridRow,列等,但是要為該網格的周圍區域設置樣式,可以樣式化嗎?

干杯

如果要更改RowDetails的背景,請執行以下操作:

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

...

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

剛檢查回來,我有一個嵌套的網格,但使用了彩色標題欄可以更好地區分父網格和嵌套網格。

在此處輸入圖片說明

還是可以通過代碼來完成? 檢測行何時具有行詳細信息,然后將其設置為背景。 e.Row.Foreground = New SolidColorBrush With {.Color = Colors.Black}

如果將模板放在容器中並設置該容器的背景,則將填充模板控件后面的區域。 請注意,使用填充為背景提供空間以在控件周圍顯示。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM