Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 执行动画后,无法在ScatterViewItem上设置不透明度属性_C#_Wpf_Animation_Properties - Fatal编程技术网

C# 执行动画后,无法在ScatterViewItem上设置不透明度属性

C# 执行动画后,无法在ScatterViewItem上设置不透明度属性,c#,wpf,animation,properties,C#,Wpf,Animation,Properties,我目前正在通过淡出从用户界面中删除一个元素。这正如预期的那样有效 public void HideShape() { if (this.TangibleShape != null) { DoubleAnimation animation = new DoubleAnimation(); animation.From = 1.0; animation.To = 0.0; animation.AutoReverse =

我目前正在通过淡出从用户界面中删除一个元素。这正如预期的那样有效

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,但
有形Shape.Shape
(它是
散点视图项
)会忽略该命令。如果我再次淡出,元素将变得可见并立即开始淡出。我不知道如何解决这个问题。有人给我一个提示吗

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
    }
}

在此处找到答案:

这是因为动画时间线仍保留DependencyProperty,您必须重置DependencyProperty,您可以使用
TangibleShape.BeginAnimation(FrameworkElement.OpacityProperty,null)
重置
有形场景
上的OpacityProperty,它具有绑定优先级。在
s.completed
lambda中添加
this.TangibleShape.Opacity=0.0;this.TangibleShape.BeginAnimation(ScatterViewItem.OpacityProperty,null)
和您应该稍后排序,然后在需要时应用Opacity=1。我确实按照建议在
s.Completed
处理程序中添加了代码,但我仍然无法将Opacity属性设置为任何值。。。还有什么我可以尝试的吗?解决方案:ScatterViewItems在这种情况下有点特殊:)如果你自己找到了解决方案,你应该将其作为答案发布。一天后,你可以将其标记为已接受的答案,你会得到一个闪亮的新徽章!