Some time ago i wrote a small widget-like application which was supposed to keep track of tasks, each task had a deadline specified as a DateTime
, now if you want to display how much time is left until the deadline you might want to bind to a "virtual" (*curses the virtual
keyword*) property like this:
public TimeSpan TimeLeft
{
get { return Deadline - DateTime.Now; }
}
Obviously in theory this property changes every tick and you want to update your UI every now and then (e.g. by periodically pumping out a PropertyChanged
event for that property).
Back when i wrote the widget i refreshed the whole task list every minute, but this is hardly ideal since if the user interacts with some item (e.g. by typing in a TextBox which binds to a Comments
-property) that will be harshly interupted and updates to the source get lost.
So what might be the best approach to updating the UI if you have time-dependent properties like this?
(I don't use that application anymore by the way, just thought this was a very interesting question)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…