c#中动态类型的动画对象

本文关键字:动画 对象 类型 动态 | 更新日期: 2023-09-27 18:10:37

所以我正在传递一个窗口到一个dll,在那里我接收它作为类型为dynamic的对象

dynamic theWindow = ...;

我需要动画窗口的属性,我尝试以下:

theWindow.BeginAnimation(theWindow.LeftProperty, _leftAnimation);

但它不起作用。所以我采取的步骤是检查如果我可以访问theWindow.LeftProperty,但我得到以下异常:

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Member 'System.Windows.Window.LeftProperty' cannot be accessed with an instance reference; qualify it with a type name instead
   at CallSite.Target(Closure , CallSite , Object )
   at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
   at blablabla ...

它说"用类型名来限定它",但我不知道这是什么意思…

然而,属性是可访问的,并按预期工作:

theWindow.MaxWidth = theWindow.Width + 108;

谢谢你的帮助

c#中动态类型的动画对象

Window.LeftProperty是静态方法,不能动态访问。你可以试试

theWindow.BeginAnimation(Window.LeftProperty, _leftAnimation);