从代码背后运行动画

时间:2013-09-05 21:51:38

标签: c# .net animation storyboard windows-phone

我有故事板,而不是我想要从代码背后的按钮上应用。 我的故事板在view.cs类中定义,就像这样..

private const string ANIMATION_FOCUSREGIONTEXT =
@"<Storyboard xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
        <DoubleAnimation Duration=""0:0:0.25"" To=""0"" RepeatBehavior=""Forever"" Storyboard.TargetProperty=""(UIElement.Opacity)"">
            <DoubleAnimation.EasingFunction>
                <ExponentialEase EasingMode=""EaseIn"" Exponent=""3"" />
            </DoubleAnimation.EasingFunction>
        </DoubleAnimation>
    </Storyboard>";

    private Storyboard _focusregionStoryborad = XamlReader.Load(ANIMATION_FOCUSREGIONTEXT) as Storyboard;

当我试着这个..

 Button asd = new Button();
            asd.Width = 100;
            asd.Visibility = Visibility.Visible;
            asd.Background = new SolidColorBrush(Colors.Red);

            videoRectangle.Children.Add(asd);

 Storyboard.SetTargetName(_focusregionStoryborad, "asd");
            _focusregionStoryborad.Completed += _focusregionStoryborad_Completed;
           _focusregionStoryborad.Begin();  // error

异常 System.InvalidOperationException 来到这一行

_focusregionStoryborad.Begin();

我错过了什么..非常感谢...

0 个答案:

没有答案