Wpf animate background color

前端 未结 8 2066
生来不讨喜
生来不讨喜 2020-11-30 02:41

I need help in taking right decision. I need to animate a background color of my user control when some event happens. When it is, I want to change the background just for 1

8条回答
  •  盖世英雄少女心
    2020-11-30 03:42

            ColorAnimation colorChangeAnimation = new ColorAnimation();
            colorChangeAnimation.From = VariableColour;
             colorChangeAnimation.To = BaseColour;
            colorChangeAnimation.Duration = timeSpan;
    
            PropertyPath colorTargetPath = new PropertyPath("(Panel.Background).(SolidColorBrush.Color)");
            Storyboard CellBackgroundChangeStory = new Storyboard();
            Storyboard.SetTarget(colorChangeAnimation, BackGroundCellGrid);
            Storyboard.SetTargetProperty(colorChangeAnimation, colorTargetPath);
            CellBackgroundChangeStory.Children.Add(colorChangeAnimation);
            CellBackgroundChangeStory.Begin();
    

    //VariableColour & BaseColour are class of Color, timeSpan is Class of TimeSpan, BackGroundCellGrid is class of Grid;

    //no need to create SolidColorBrush and binding to it in XAML; //have fun!

提交回复
热议问题