我在查找带有名称的生成故事板时遇到问题。我不能使用类变量,因为这段代码被多次调用并且返回是异步的。
您可以查看我的其他问题以获取更多信息:这里
我的代码:
private void refreshPostIt(int index)
{
Button btn = // Button to rotate
Storyboard sb = new Storyboard();
sb.Name = "sb" + postItIndex;
Storyboard.SetTarget(rotate, btn);
Storyboard.SetTargetName(rotate, btn.Name);
Storyboard.SetTargetProperty(rotate, new PropertyPath("(UIElement.RenderTransform).(RotateTransform.Angle)"));
sb.Children.Add(rotate);
sb.Begin(btn, true);
// Asynchronous call
BackgroundWorker bgw = new BackgroundWorker();
bgw.DoWork += new DoWorkEventHandler(bgw_DoWork);
bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);
bgw.RunWorkerAsync(postItIndex);
}
private void bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
int postItIndex = // Retrieved from e.Arguments
Button btn = // Find the Button thanks to the postItIndex
Storyboard sb = // Here is my problem, how to find the Storyboard
if (sb != null)
{
// Stop rotation
//sb.Stop(btn);
}
}