0

我目前正在通过淡出它来从用户界面中删除一个元素。这按预期工作。

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(它是 a ScatterViewItem)忽略该命令。如果我再次淡出,元素变得可见并立即开始淡出。我不知道如何解决这个问题。有人对我有提示吗?

4

1 回答 1

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-

于 2013-07-05T22:13:54.900 回答