0
我有一個datagrid(Xceed社區版本3.1.0)包含一般發票信息。其中一個字段包含發票的到期日期。我想爲具有到期日期的行使用不同的顏色。爲了達到這個目的,我使用了一個值轉換器。 這裏是我的XAML:Xceed datagrid - 基於DateTime值更改datarow顏色
<dg:DataGridControl.Resources>
<Style TargetType="{x:Type dg:DataRow}" BasedOn="{StaticResource DefaultDataRowStyle}">
<Setter Property="Background" Value="{Binding DocumentDueDate, Converter={StaticResource DueDateToBrushConverter}}"/>
<!--<Setter Property="Background" Value="OrangeRed"/>-->
</Style>
</dg:DataGridControl.Resources>
<dg:DataGridControl.Columns>
<dg:Column Title="{bx:LocalizeBinding Type, Global=True}" FieldName="MovementType" Width="45"/>
<dg:Column Title="{bx:LocalizeBinding Number, Global=True }" FieldName="DocumentNumber" Width="90"/>
<dg:Column Title="{bx:LocalizeBinding Date, Global=True }" FieldName="DocumentDate" Width="90"/>
<dg:Column Title="{bx:LocalizeBinding DueDate, Global=True }" FieldName="DocumentDueDate" Width="90"/>
<dg:Column Title="{bx:LocalizeBinding Debit, Global=True }" FieldName="Debit" CellHorizontalContentAlignment="Right" Width="80">
<dg:Column.CellContentTemplate>
<DataTemplate>
<TextBlock Text="{Binding StringFormat=N2}" HorizontalAlignment="Right"/>
</DataTemplate>
</dg:Column.CellContentTemplate>
</dg:Column>
<dg:Column Title="{bx:LocalizeBinding Credit, Global=True }" FieldName="Credit" CellHorizontalContentAlignment="Right" Width="80">
<dg:Column.CellContentTemplate>
<DataTemplate>
<TextBlock Text="{Binding StringFormat=N2}" HorizontalAlignment="Right"/>
</DataTemplate>
</dg:Column.CellContentTemplate>
</dg:Column>
<dg:Column Title="{bx:LocalizeBinding Balance, Global=True }" FieldName="Balance" CellHorizontalContentAlignment="Right">
<dg:Column.CellContentTemplate>
<DataTemplate>
<TextBlock Text="{Binding StringFormat=N2}" HorizontalAlignment="Right"/>
</DataTemplate>
</dg:Column.CellContentTemplate>
</dg:Column>
<dg:Column Title="{bx:LocalizeBinding Difference, Global=True }" FieldName="Difference" CellHorizontalContentAlignment="Right">
<dg:Column.CellContentTemplate>
<DataTemplate>
<TextBlock Text="{Binding StringFormat=N2}" HorizontalAlignment="Right"/>
</DataTemplate>
</dg:Column.CellContentTemplate>
</dg:Column>
<dg:Column Title="{bx:LocalizeBinding Currency, Global=True }" FieldName="Currency" Width="70"/>
<dg:Column Title="{bx:LocalizeBinding Description, Global=True }" FieldName="Description" Width="250" TextWrapping="Wrap">
</dg:Column>
</dg:DataGridControl.Columns>
<dg:DataGridControl.View>
<dg:TableView/>
</dg:DataGridControl.View>
這是我的轉換器類:
public class DueDateToBrushConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
DateTime? input = value as DateTime?;
if (input.HasValue && input < DateTime.Now)
return Brushes.OrangeRed;
else
return Brushes.Transparent;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
我把一個斷點在轉換器和代碼被執行,但該行的顏色沒有改變。將顏色設置爲固定顏色(如在註釋行中)可以很好地工作。我不知道我在做什麼錯。任何幫助將非常感激。