我想要淡出FlowDocument
TableRow
。
var opacityAnimation = new DoubleAnimation();
opacityAnimation.To = 0.0;
opacityAnimation.Duration = TimeSpan.FromSeconds(1);
Storyboard.SetTarget(opacityAnimation, row.Foreground);
Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath(SolidColorBrush.OpacityProperty));
var storyboard = new Storyboard();
storyboard.Children.Add(opacityAnimation);
storyboard.Begin();
无法制作动画'(0)'在不可变对象实例上。我遇到了麻烦,因为它似乎无法直接操纵不透明度,您必须更改Brush
前景TableRow
。
我应该以故事板为目标?
答案 0 :(得分:1)
通过以下微小的更改,我设法为表格行设置动画:
row.Foreground = new SolidColorBrush(Colors.Black);
var opacityAnimation = new DoubleAnimation();
opacityAnimation.From = 1.0;
opacityAnimation.To = 0.0;
opacityAnimation.Duration = TimeSpan.FromSeconds(1);
Storyboard.SetTarget(opacityAnimation, row);
Storyboard.SetTargetProperty(opacityAnimation,
new PropertyPath("(TableRow.Foreground).(Brush.Opacity)"));
var storyboard = new Storyboard();
storyboard.Children.Add(opacityAnimation);
storyboard.Begin();
必须新创建前景画笔,使其不被冻结(=不可动画);看第一行代码。此外,目标属性路径必须为"(TableRow.Foreground).(Brush.Opacity)"
,目标必须是行本身,而不是row.Foreground
。