I am trying to create a DataGrid and I want to bind one of the Foreground TextColums properties to a date so that it turns red if the date is in the past.
Here is the XAML:
<toolkit:DataGridTextColumn
Binding="{Binding Path=Prüfdatum, Converter={StaticResource TimestampToDateConverter}}"
Header="Prüfdatum"
Foreground="{Binding Path=Prüfdatum, Converter={StaticResource TimestampToColorConverter},
ConverterParameter=Prüfdatum}" />
Here is my converter:
class TimestampToColorConverter: IValueConverter
{
#region IValueConverter Member
public object Convert(object value, Type targetType,
object parameter, System.Globalization.CultureInfo culture)
{
string Datum = value.ToString();
int year = System.Convert.ToInt32(Datum.Substring(6, 4));
int month = System.Convert.ToInt32(Datum.Substring(3, 2));
int day = System.Convert.ToInt32(Datum.Substring(0, 2));
int hour = System.Convert.ToInt32(Datum.Substring(11, 2));
int minute = System.Convert.ToInt32(Datum.Substring(14, 2));
int second = System.Convert.ToInt32(Datum.Substring(17, 2));
DateTime Time = new DateTime(year, month, day, hour, minute, second);
if (Time < System.DateTime.Now)
{
return Brushes.Red as Brush;
}
else
{
return Brushes.Black as Brush;
}
}
public object ConvertBack(object value, Type targetType,
object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
#endregion
}
I don’t know what’s wrong, but the converter is not even a frame (the first converter works fine). The output window shows the following:
System.Windows.Data error: 2: Cannot find a FrameworkElement or FrameworkContentElement control for the target element. BindingExpression: Path = Prüfdatum; DataItem = NULL; target element is 'DataGridTextColumn' (HashCode = 16187528); target property "Foreground" (type "Brush")
Hope you help me guys.
thank