我收到错误消息无法解析 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在你说重新发布之前。这个问题必须处理 mutlipages 而我只是想开始一个动画。
堆栈跟踪
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:
最佳答案
而不是使用
Storyboard.SetTargetName(da, pGrid.Name);
尝试
Storyboard.SetTarget(da, pGrid);
关于c# - 无法解析 TargetName - Silverlight4 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2511080/