Adam Rackis
Adam Rackis

Reputation: 83356

Setting Storyboards TargetName in Code

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;
            }

            Control toPopup = AvailablePopups.Pop();
            toPopup.DataContext = I;

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

            this.sbShowPopup.Begin();
        });

Upvotes: 0

Views: 511

Answers (1)

Adam Rackis
Adam Rackis

Reputation: 83356

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

sbShowPopup.Stop();

Upvotes: 1

Related Questions