I am having trouble with my converter, I have a DateTime column in my DataGrid which I subtract from the systems current time to get the total minutes difference and then from there if total minutes is less than or equal to 60 minutes my DataGrid
Row should change colour to RED. The problem I have is every row is changing.
in runtime my code it seems to be subtracting the two times okay, not really sure what is happening.
C#
using System;
using System.Windows.Data;
namespace Project
{
[ValueConversion(typeof(DateTime), typeof(bool))]
public class TimeValueConverter:IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
DateTime end = (DateTime)value;
DateTime curtime = DateTime.Now;
TimeSpan span = curtime - end;
var totalMinutes = span.Minutes;
if (totalMinutes <= 60)
{
return true;
}
else
{
return false;
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
instead of span.Minutes, use span.TotalMinutes. you will get the total minutes difference instead of only minute part you were getting using span.Minutes
None
0 Points
1 Post
If total minutes is less than or equal to 60 minutes then return true - IValueConverter
Dec 20, 2019 09:53 AM|lyonsTheWay|LINK
I am having trouble with my converter, I have a DateTime column in my DataGrid which I subtract from the systems current time to get the total minutes difference and then from there if total minutes is less than or equal to 60 minutes my DataGrid Row should change colour to RED. The problem I have is every row is changing.
in runtime my code it seems to be subtracting the two times okay, not really sure what is happening.
C#
XAML
Member
6 Points
16 Posts
Re: If total minutes is less than or equal to 60 minutes then return true - IValueConverter
Dec 23, 2019 06:28 AM|pjanicked|LINK
instead of span.Minutes, use span.TotalMinutes. you will get the total minutes difference instead of only minute part you were getting using span.Minutes