使用DispatcherTimer淡化

时间:2018-05-24 08:33:48

标签: c# xaml uwp dispatchertimer

在我的uwp项目中,我在图片上有3种不同的颜色叠加(绿色,黄色和红色)。这些颜色应该表示是否预订了房间(在这种情况下房间是图片)。

如果预订了房间,则应淡出green color并淡出red color,然后在7秒后,red color应淡出至yellow color,然后最后yellow color应该再次淡出green color

  1. 对于淡入淡出我使用Windows Animation extension for UWP
  2. Green Color设置为默认值。
  3. 现在当预订房间时,第一个淡入淡出功能正在工作(红色到黄色),但YellowGreen没有消失。

        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是保存颜色叠加层的矩形。

1 个答案:

答案 0 :(得分:0)

解决了问题!

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();
            }