【问题标题】:Cannot set Opacity property on ScatterViewItem after an animation has been performed执行动画后无法在 ScatterViewItem 上设置 Opacity 属性
【发布时间】: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.completed lambda 中添加 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


【解决方案1】:
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);
        animation.FillBehavior = FillBehavior.Stop; // needed

        Storyboard s = new Storyboard();
        s.Children.Add(animation);

        Storyboard.SetTarget(animation, this.TangibleShape.Shape);
        Storyboard.SetTargetProperty(animation, new PropertyPath(ScatterViewItem.OpacityProperty));

        s.Completed += delegate(object sender, EventArgs e)
        {
            // call UIElementManager to finally hide the element
            UIElementManager.GetInstance().Hide(this.TangibleShape);
            this.TangibleShape.Shape.Opacity = 0.0; // otherwise Opacity will be reset to 1
        };
        s.Begin(this.TangibleShape.Shape); // moved to the end
    }
}

在这里找到答案:http://social.msdn.microsoft.com/Forums/en-US/7d33ca82-2c02-4004-8b37-47edf4cca34e/scatterviewitem-and-

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 2022-08-19
    • 1970-01-01
    • 1970-01-01
    • 2014-12-31
    • 1970-01-01
    • 2020-11-02
    相关资源
    最近更新 更多