麻烦创建双重动画

时间:2016-02-25 18:08:04

标签: c# wpf

我正在为后面的代码中的WPF中的文本块创建一个闪烁动画。我知道文本块作为opacity属性,但这段代码似乎无法找到它。我做错了什么?

DoubleAnimation da = new DoubleAnimation
{
    From = 1,
    To = 0,
    Duration = new Duration(TimeSpan.FromSeconds(0.5)),
    AutoReverse = true,
    RepeatBehavior = RepeatBehavior.Forever
};
myTextBlock.BeginAnimation(Opacity, da);

另外,我正在尝试创建一个颜色动画。这看起来似乎也不起作用:

ColorAnimation ca = new ColorAnimation
{
    From = Colors.Red,
    To = Colors.Black,
    Duration = new Duration(TimeSpan.FromSeconds(1)),
    AutoReverse = true,
    RepeatBehavior = RepeatBehavior.Forever
};
myTextBlock.Background.BeginAnimation(SolidColorBrush.ColorProperty, ca);

3 个答案:

答案 0 :(得分:2)

动画应用于Property,而不是Field。此外,它似乎使用父的不透明度,而不是TextBlock。

Opacity更改为UIElement.OpacityProperty

DoubleAnimation da = new DoubleAnimation
{
    From = 1,
    To = 0,
    Duration = new Duration(TimeSpan.FromSeconds(0.5)),
    AutoReverse = true,
    RepeatBehavior = RepeatBehavior.Forever
};
myTextBlock.BeginAnimation(UIElement.OpacityProperty, da);

答案 1 :(得分:1)

source 'https://rubygems.org'

ruby '2.1.2'

gem 'sinatra', '>= 1.4.5', '~> 1.4'
gem 'sinatra-contrib', '>= 1.4.2', '~> 1.4'
gem 'dm-core', '>= 1.2.0', '~> 1.2'
gem 'dm-sqlite-adapter', '>= 1.2.0', '~> 1.2'
gem 'dm-validations', '>= 1.2.0', '~> 1.2'
gem 'dm-timestamps', '>= 1.2.0', '~> 1.2'
gem 'dm-migrations', '>= 1.2.0', '~> 1.2'

group :development, :test do
  gem 'timecop'
  gem 'simplecov'
  gem 'minitest'
end

答案 2 :(得分:0)

您的代码适合我。您是否先将背景颜色设置为红色?如果不是,请尝试将背景颜色设置为红色。