So I am trying to add a timer into a new column "Duration" that subtracts the time started, which is a date time, and displays how long it has been active. So far this is what I have:
XAML:
<DataGridTextColumn Binding="{Binding BlockName}" Header="Block" Width="200"/>
<DataGridTextColumn Binding="{Binding Auditor}" Header="Auditor" Width="200"/>
<DataGridTextColumn Binding="{Binding AcctAuditor}" Header="Accounting Auditor" Width="200"/>
<DataGridTextColumn Binding="{Binding BlockLeader}" Header="Block Leader" Width="200"/>
<DataGridTextColumn x:Name="TimeStarted" Binding="{Binding TimeStarted}" Header="Started" Width="200"/>
<DataGridTextColumn x:Name="Duration" Header="Elapsed Time" Width="200"/>
Code Behind:
System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
dispatcherTimer.Tick += dispatcherTimer_Tick;
dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
dispatcherTimer.Start();
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
foreach (DataRowView dr in BlockStatus.ItemsSource)
{
var diff = dr.Row.Field<DateTime>("TimeStarted").Subtract(DateTime.Now);
if (diff.TotalSeconds > 0)
{
dr.Row["Duration"] = string.Format("{0} d {1:D2}:{2:D2}:{3:D2}", diff.Days, diff.Hours, diff.Minutes, diff.Seconds);
}
else
{
dr.Row["Duration"] = "0 d 00:00:00";
}
}
}
I am trying to have a column that will count up in mm:ss in a new column based on another column.
Here is a picture of an example:
https://prnt.sc/q2vrw3[
^]
What I have tried:
I asked before, but I've reworded and hopefully I have explained it well enough