【发布时间】:2010-03-24 20:17:52
【问题描述】:
我收到错误无法解析 TargetName grdGeneral。我想要做的是有一个淡出功能,它接受一个网格并将不透明度淡化为零。我在 MouseLeftButtonDown 上调用了这个函数,并在 xaml 和表单加载之后加载。
调用淡出:
private void imgNext_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
fadeOut(grdGeneral);
}
淡出功能:
private void fadeOut(Grid pGrid)
{
Storyboard stb = new Storyboard();
DoubleAnimation da = new DoubleAnimation();
da.From = 1.0;
da.To = 0.0;
stb.Duration = new Duration(TimeSpan.FromSeconds(.75));
stb.Children.Add(da);
Storyboard.SetTargetName(da, pGrid.Name);
Storyboard.SetTargetProperty(da, new PropertyPath(Grid.OpacityProperty));
stb.Begin();
}
我访问过一些教程网站,我的代码似乎遵循相同的顺序。在你说重新发布之前,我也一直在这个 stackoverflow question 上。这个问题必须处理多页,我只是想开始一个动画。
堆栈跟踪
System.InvalidOperationException was unhandled by user code
Message=Cannot resolve TargetName grdGeneral.
StackTrace:
at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
at MS.Internal.XcpImports.MethodEx(DependencyObject obj, String name)
at System.Windows.Media.Animation.Storyboard.Begin()
at MeterTesting.QuarterReportGUI.fadeOut(Grid pGrid)
at MeterTesting.QuarterReportGUI.imgNext_MouseLeftButtonDown(Object sender, MouseButtonEventArgs e)
at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)
InnerException:
【问题讨论】:
-
可能是 Silverlight4 中的一个错误。对于那些有兴趣使用 Phil 的方式并且比尝试在代码中找到方式更好的人。 betaforums.silverlight.net/forums/p/23517/84087.aspx
-
遇到了同样的问题。我绝对需要运行时创建的东西。解决方案是什么?上面的链接坏了。
标签: c# silverlight animation silverlight-4.0