Using a Storyboard animation on a programmatically-added control

后端 未结 4 1810
不知归路
不知归路 2020-12-13 12:42

I\'m trying to fade in a new control to my application\'s \"app\" area which is programmatically added after the existing controls are removed. My code looks like this:

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 13:28

    I agree, the namescopes are probably the wrong thing to use for this scenario. Much simpler and easier to use SetTarget rather than SetTargetName.

    In case it helps anyone else, here's what I used to highlight a particular cell in a table with a highlight that decays to nothing. It's a little like the StackOverflow highlight when you add a new answer.

        TableCell cell = table.RowGroups[0].Rows[row].Cells[col];
    
        // The cell contains just one paragraph; it is the first block
        Paragraph p = (Paragraph)cell.Blocks.FirstBlock;
    
        // Animate the paragraph: fade the background from Yellow to White,
        // once, through a span of 6 seconds.
    
        SolidColorBrush brush = new SolidColorBrush(Colors.Yellow);
        p.Background = brush;
        ColorAnimation ca1 = new ColorAnimation()
        {
                From = Colors.Yellow,
                To = Colors.White,
                Duration = new Duration(TimeSpan.FromSeconds(6.0)),
                RepeatBehavior = new RepeatBehavior(1),
                AutoReverse = false,
        };
    
        brush.BeginAnimation(SolidColorBrush.ColorProperty, ca1);
    

提交回复
热议问题