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();
精彩评论