呼唤淡出:
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:解决方法 如果你不是必须的话,你真的不应该尝试编写这样的故事板.一旦你的动画变得有点复杂,它就会咬你.
您应该在xaml中执行此 *** 作,最好使用Blend.在你的xaml中尝试这个:
<UserControl.Resources> <Storyboard x:name="FadeGrID"> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.Targetname="GrdGeneral"> <EasingDoubleKeyFrame KeyTime="0" Value="1"/> <EasingDoubleKeyFrame KeyTime="0:0:0.7" Value="0"/> </DoubleAnimationUsingKeyFrames> </Storyboard></UserControl.Resources><GrID x:name="GrdGeneral" Background="White"> <Image x:name="imgNext" MouseleftbuttonDown="imgNext_MouseleftbuttonDown" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Source="/StoryboardInCode;component/Images/avatar.jpg"></Image></GrID>
在您的代码中,您将调用它,如下所示:
private voID imgNext_MouseleftbuttonDown(object sender,MousebuttonEventArgs e) { FadeGrID.Begin(); }
这应该会给你你想要的东西.
使用按钮代替图像也会更好.
总结以上是内存溢出为你收集整理的无法解析TargetName – Silverlight4 C#全部内容,希望文章能够帮你解决无法解析TargetName – Silverlight4 C#所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)