使用 DispatcherTimer 淡入淡出
Fade with a DispatcherTimer
在我的 uwp
项目中,我在图片上叠加了 3 种不同的颜色(绿色、黄色和红色)。这些颜色应该表示房间(在这种情况下房间是一张照片)是否被预订。
如果房间已预订,它应该淡出 green color
并淡出 red color
,然后在 7 秒后 red color
应该淡出 yellow color
,最后 yellow color
应该再次淡出到 green color
。
- 对于淡入淡出,我使用
Windows Animation extension for UWP
。
Green Color
设置为默认值。
现在,当房间被预订时,第一个渐变正在工作(红色到黄色),但是 Yellow
到 Green
没有渐变。
public void RedIndicatorColorToYellowIndicatorColor()
{
StatusColor.Fade(duration: 1000, delay: 2000, value: 0).Start();
StatusColor.Fill = RedBrush;
DispatcherTimer ColorTimer = new DispatcherTimer();
ColorTimer.Interval = TimeSpan.FromSeconds(7);
ColorTimer.Tick += (Sender, args) =>
{
YellowindIcatorColorToGreenIndicatorColor();
ColorTimer.Stop();
};
ColorTimer.Start();
}
public void YellowindIcatorColorToGreenIndicatorColor()
{
StatusColor.Fade(duration: 1000, delay: 0, value: 1).Start();
StatusColor.Fill = YellowBrush;
DispatcherTimer ColorTimer2 = new DispatcherTimer();
ColorTimer2.Interval = TimeSpan.FromSeconds(7);
ColorTimer2.Tick += (Zender, Args) =>
{
StatusColor.Fill = GreenBrush;
ColorTimer2.Stop();
};
ColorTimer2.Start();
}
StatusColor
是包含颜色叠加层的矩形。
问题解决了!
public void RedIndicatorColorToYellowIndicatorColor()
{
StatusColor.Fill = GreenBrush;
DispatcherTimer ColorTimer = new DispatcherTimer();
ColorTimer.Interval = TimeSpan.FromSeconds(7);
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();
YellowindIcatorColorToGreenIndicatorColor();
ColorTimer.Stop();
};
ColorTimer.Start();
}
public void YellowindIcatorColorToGreenIndicatorColor()
{
DispatcherTimer ColorTimer2 = new DispatcherTimer();
ColorTimer2.Interval = TimeSpan.FromSeconds(7);
ColorTimer2.Tick += async (Zender, Args) =>
{
await StatusColor.Fade(duration: 1000, delay: 0, value: 0).StartAsync();
StatusColor.Fill = YellowBrush;
await StatusColor.Fade(duration: 1200, delay: 0, value: 1).StartAsync();
red2green();
ColorTimer2.Stop();
};
ColorTimer2.Start();
}
在我的 uwp
项目中,我在图片上叠加了 3 种不同的颜色(绿色、黄色和红色)。这些颜色应该表示房间(在这种情况下房间是一张照片)是否被预订。
如果房间已预订,它应该淡出 green color
并淡出 red color
,然后在 7 秒后 red color
应该淡出 yellow color
,最后 yellow color
应该再次淡出到 green color
。
- 对于淡入淡出,我使用
Windows Animation extension for UWP
。 Green Color
设置为默认值。
现在,当房间被预订时,第一个渐变正在工作(红色到黄色),但是 Yellow
到 Green
没有渐变。
public void RedIndicatorColorToYellowIndicatorColor()
{
StatusColor.Fade(duration: 1000, delay: 2000, value: 0).Start();
StatusColor.Fill = RedBrush;
DispatcherTimer ColorTimer = new DispatcherTimer();
ColorTimer.Interval = TimeSpan.FromSeconds(7);
ColorTimer.Tick += (Sender, args) =>
{
YellowindIcatorColorToGreenIndicatorColor();
ColorTimer.Stop();
};
ColorTimer.Start();
}
public void YellowindIcatorColorToGreenIndicatorColor()
{
StatusColor.Fade(duration: 1000, delay: 0, value: 1).Start();
StatusColor.Fill = YellowBrush;
DispatcherTimer ColorTimer2 = new DispatcherTimer();
ColorTimer2.Interval = TimeSpan.FromSeconds(7);
ColorTimer2.Tick += (Zender, Args) =>
{
StatusColor.Fill = GreenBrush;
ColorTimer2.Stop();
};
ColorTimer2.Start();
}
StatusColor
是包含颜色叠加层的矩形。
问题解决了!
public void RedIndicatorColorToYellowIndicatorColor()
{
StatusColor.Fill = GreenBrush;
DispatcherTimer ColorTimer = new DispatcherTimer();
ColorTimer.Interval = TimeSpan.FromSeconds(7);
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();
YellowindIcatorColorToGreenIndicatorColor();
ColorTimer.Stop();
};
ColorTimer.Start();
}
public void YellowindIcatorColorToGreenIndicatorColor()
{
DispatcherTimer ColorTimer2 = new DispatcherTimer();
ColorTimer2.Interval = TimeSpan.FromSeconds(7);
ColorTimer2.Tick += async (Zender, Args) =>
{
await StatusColor.Fade(duration: 1000, delay: 0, value: 0).StartAsync();
StatusColor.Fill = YellowBrush;
await StatusColor.Fade(duration: 1200, delay: 0, value: 1).StartAsync();
red2green();
ColorTimer2.Stop();
};
ColorTimer2.Start();
}