I'm currently working on a UWP
project and need some help with my DispatcherTimer
.
What I'm working with is a booking function and I want a color to change if there is 15 seconds left until the DispatcherTimer
ticks.
I have two variables that is named timefrom
and timeTo
and they come from a SQL
database. So what I want to do is to first change a color from Green
to Red
and then stay Red
until there is 15 seconds left until the timeto = DateTime.UtcNow
"timefrom": "2018-02-17T14:00:00"
"timeto": "2018-02-17T15:15:00"
Right now, what I have tried with is this:
if (timeto < DateTime.UtcNow)
{
StatusColor.Fill = GreenBrush;
}
else if (timeto > DateTime.UtcNow)
{
GreenToRed();
}
This is my DispatcherTimer
:
public void GreenToRed()
{
DispatcherTimer ColorTimer = new DispatcherTimer();
ColorTimer.Interval = TimeSpan.FromSeconds(3);
ColorTimer.Tick += async (Sender, args) =>
{
await StatusColor.Fade(duration: 1000, delay: 0, value: 0).StartAsync();
StatusColor.Fill = RedBrush;
await StatusColor.Fade(duration: 1200, delay: 0, value: 1).StartAsync();
RedToYellow();
ColorTimer.Stop();
};
ColorTimer.Start();
}
- StatusColor is a retangle that is suposed to contain the color as a fill.
- GreenBrush, RedBrush and YellowBrush is the three colors that I want to switch between.
Thanks in advance!