我有这个问题,我似乎无法克服。也许有人可以帮忙。
我正在创建一种动态创建 DoubleAnimations 的方法。我会从一个数组中为它提供一组不同的用户控件,它会自动创建 DoubleAnimations 以添加到 StoryBoard。
问题是,我需要插入两种类型的 PropertyPath:PlaneProjection.RotationYProperty和Control.OpacityProperty。我必须为它们设置不同的Storyboard.SetTarget,所以我需要一种方法来比较我在方法中调用 TargetProperty 的 PropertyPath 参数。为了解释这里是我试图在代码中做的一部分:
if (TargetProperty == new PropertyPath (PlaneProjection.RotationYProperty))
{
// Do some code
projection = control.Projection as PlaneProjection;
Storyboard.SetTarget(doubleAnimation, projection);
}
else if (TargetProperty == new PropertyPath (Control.OpacityProperty))
{
Storyboard.SetTarget(doubleAnimation, control);
}
我可以通过使用 bool 作为解决方法开关来使我的方法工作,但如果可能的话,我仍然希望减少方法中的参数数量。
我试过使用:
if (TargetProperty.ToString() == new PropertyPath (PlaneProjection.RotationYProperty).ToString())
... 和...
if (TargetProperty.Equals(new PropertyPath (PlaneProjection.RotationYProperty)))
...但他们都没有工作。有什么想法可以解决这个问题吗?难道我做错了什么?
提前致谢!