2013-04-17 25 views
2

我挣扎着看似简单的问题: 我有一个绑定到数据表的数据网格。此Datatable包含一个名为“COLORSTATUS”(一个枚举值)的列 - 我想根据ColorStatus绘制Datatable的每个行。 我试图建立一个值转换器 - 但我无法传递它整行和/或Datatable。 我对使用Caliburns消息连接DataGridRow事件充满了厌倦 - 但是如何在XAML中执行此操作 - 我只能使用DataGrid.RowStyle元素。根据数据表更改Datagrid行的背景值

<DataGrid x:Name="excelDataTable_ExcelData" cal:Message.Attach="[Event AutoGeneratedColumns] = [Action HideTheColorColumn($source)]"> 
      ?? What to do here 
</DataGrid> 

我看中了这个解决方案:

<DataGrid.RowStyle> 
     <Style TargetType="DataGridRow"> 
      <Setter Property="Background" Value="{Binding Row, Converter={StaticResource ExcelRowColorConverter}}"></Setter> 
     </Style> 
    </DataGrid.RowStyle> 

我有点惊喜的,你可以通过 “行”。 作为转换器的提示:传递的对象是实际的DataRow。

回答

1

转换器应该可以正常工作,但您需要确保将其应用到正确的位置。

只需通过DataRow,从中获取“COLORSTATUS”列值,然后返回相应的颜色画笔。

例如,

<DataGrid.Resources> 
    <Style TargetType="{x:Type DataGridRow }"> 
     <!-- DataContext will be your DataRow --> 
     <Setter Property="Background" 
       Value="{Binding Converter={StaticResource MyColorConverter}}" /> 
    </Style> 
</DataGrid.Resources> 
+0

感谢您为您的文章 - 我带着一个影响无关soultion,但你也行。 –

相关问题