2013-12-09 85 views
1

我在WPF中有一個datagrid,其中一列是我想要設置的行的顏色。如何將行的顏色設置爲該字段的值(例如#FF7B68EE)?將datagrid行顏色綁定到WPF中的單元格值

<DataGrid Grid.Column="0" Grid.Row="4" Name="dgBank" ItemsSource="{Binding Path=bankTable.dataTable.DefaultView}" AutoGenerateColumns="TRUE" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" /> 
+1

看看這個鏈接:http://stackoverflow.com/questions/7339509/how-do-i-bind-the-background-of-a-data-grid-row-to-特定顏色 – codeBlue

+0

@codeBlue工作,謝謝。 – donL

回答

1

我使用@codeBlue在我的問題的評論中指向我的答案。 How do I bind the background of a data grid row to specific color?

<DataGrid Grid.Column="0" Grid.Row="4" Name="dgBank" ItemsSource="{Binding Path=bankTable.dataTable.DefaultView}" AutoGenerateColumns="TRUE" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False"> 
    <DataGrid.RowStyle> 
     <Style TargetType="DataGridRow"> 
      <Setter Property="Background" Value="{Binding colorColumn}"/> 
     </Style> 
    </DataGrid.RowStyle> 
</DataGrid> 
相關問題