Animation breaks binding

给你一囗甜甜゛ 提交于 2019-12-02 07:57:20

问题


I have a ComboBox whose Opacity property has the following binding:

Opacity="{Binding ElementName=stackPanel, Path=IsMouseOver, Converter={StaticResource mouseOverConverter}}"

Basically, if the IsMouseOver property is true, the ComboBox has an Opacity of 1, otherwise 0.4.

Now I apply this animation to the ComboBox:

private void AnimateComboBox()
{
  DoubleAnimation da = new DoubleAnimation();
  da.From = 0.4;
  da.To = 1;
  da.Duration = TimeSpan.FromSeconds(0.8);
  da.AutoReverse = true;

  ComboClassList.BeginAnimation(ComboBox.OpacityProperty, da);  
}

That works well, but afterwards the binding of the ComboBox doesn't work anymore. The Opacity doesn't change when I move my mouse over the StackPanel. Why does the animation break my binding? Snoop says, the binding still exists, altough it's highlighted red in Snoop.


回答1:


The animation is by default holding the final property value. To change that, set its FillBehavior property to Stop:

var animation = new DoubleAnimation
{
    From = 0.4,
    To = 1,
    Duration = TimeSpan.FromSeconds(0.8),
    AutoReverse = true,
    FillBehavior = FillBehavior.Stop
};

When the animation ends, the property will be set back to the value provided by the binding.



来源:https://stackoverflow.com/questions/32839906/animation-breaks-binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!