【发布时间】:2013-07-02 23:30:54
【问题描述】:
我目前正在通过淡出它从用户界面中删除一个元素。这按预期工作。
public void HideShape()
{
if (this.TangibleShape != null)
{
DoubleAnimation animation = new DoubleAnimation();
animation.From = 1.0;
animation.To = 0.0;
animation.AutoReverse = false;
animation.Duration = TimeSpan.FromSeconds(1.5);
Storyboard s = new Storyboard();
s.Children.Add(animation);
Storyboard.SetTarget(animation, this.TangibleShape.Shape);
Storyboard.SetTargetProperty(animation, new PropertyPath(ScatterViewItem.OpacityProperty));
s.Begin(this.TangibleShape.Shape);
s.Completed += delegate(object sender, EventArgs e)
{
// call UIElementManager to finally hide the element
UIElementManager.GetInstance().Hide(this.TangibleShape);
};
}
}
问题是我想在某些情况下再次将不透明度设置为 1,但 TangibleShape.Shape(它是 ScatterViewItem)忽略了该命令。如果我再次淡出,元素变得可见并立即开始淡出。我不知道如何解决这个问题。有人给我提示吗?
【问题讨论】:
-
这是因为 Animations Timeline 仍然持有 DependancyProperty,你必须重置 DependancyProperty,你可以使用
TangibleShape.BeginAnimation(FrameworkElement.OpacityProperty, null);重置TangibleShape上的 OpacityProperty -
这是绑定优先级的 cos。在
s.completedlambda 中添加this.TangibleShape.Opacity = 0.0; this.TangibleShape.BeginAnimation(ScatterViewItem.OpacityProperty, null);并且您应该稍后排序,然后在需要时应用 Opacity = 1。 -
我确实按照建议在
s.Completed处理程序中添加了代码,但我仍然无法将 opacity 属性设置为任何值......还有什么我可以尝试的吗? -
解决方案:social.msdn.microsoft.com/Forums/en-US/… ScatterViewItems 在这种情况下有点特殊 :)
-
如果您自己找到了解决方案,您应该将其发布为答案。一天后,您可以将其标记为已接受的答案,您将获得一个闪亮的新徽章!
标签: c# wpf animation properties