开发者

Setting Storyboards TargetName in Code

开发者 https://www.devze.com 2023-01-24 10:52 出处:网络
Silverlight 4, but I\'m not sure if this applys to WPF also. This is some code I have to cycle through controls, and animate them.The first one works perfectly, but the second time around I get

Silverlight 4, but I'm not sure if this applys to WPF also.

This is some code I have to cycle through controls, and animate them. The first one works perfectly, but the second time around I get

System.InvalidOperationException: 2218 An Error has occurred. ... at MS.Internal.XcpImports.SetValue(...

It doesn't seem to like getting the Target name set the second time. I've also tried that line as:

sbShowPopup.SetValue(Storyboard.TargetNameProperty, toPopup.Name);

Code (it's a bit ugly - just trying to do a POC right now):

        Messenger.Default.Register<Item>(this, "O", I => {
            if (AvailablePopups.Peek() == null) {
                MessageBox.Show("Nothing available");
                return;
            }

         开发者_StackOverflow中文版   Control toPopup = AvailablePopups.Pop();
            toPopup.DataContext = I;

            try {
                Storyboard.SetTargetName(sbShowPopup, toPopup.Name);
            } catch (Exception E) {
                MessageBox.Show(E.ToString());
            }

            this.sbShowPopup.Begin();
        });


If anyone else stumbles here, you have to stop the animation before setting the target to something else:

sbShowPopup.Stop();
0

精彩评论

暂无评论...
验证码 换一张
取 消