2017-12-05 16 views
1

불투명도 특성을 올바르게 설정할 수는 있지만 Storyboard에 바인딩하지 않으면 나중에 설정할 수 있습니다.Storyboard Animation이 이미 설정 한 컨트롤에 불투명도를 직접 설정하십시오.

UserControl MyControl; 
MyControl.Opacity = 0.8; /// This works before animation set 

Storyboard sb = new Storyboard(); 
DoubleAnimation opacity = new DoubleAnimation(); 
opacity.From = 1; 
opacity.To = 0; 
opacity.Duration = TimeSpan.FromMilliseconds(400); 
Storyboard.SetTarget(opacity, MyControl); 
Storyboard.SetTargetProperty(opacity, new PropertyPath(UserControl.OpacityProperty)); 
sb.Children.Add(opacity); 
sb.Begin(); 

sb.Completed += (object sender, EventArgs e) => { 
    MyControl.Opacity = 0.5; /// This doesn't work anymore 
} 

Storyboard이 완료된 후 어떻게 작동합니까?

답변

1

경우에 따라 속성이 애니메이션 된 후에 값을 변경할 수없는 것으로 나타날 수 있습니다. 당신은 시도 할 수 있습니다 :

sb.Completed += (object sender, EventArgs e) => { 
sb.Remove(MyControl); 
    MyControl.Opacity = 0.5; 
} 

이유는 내가 시도했지만 작동하지 않았다

+0

How to: Set a Property After Animating It with a Storyboard을 설명한다. 왜 내가'MyControl'을'Storyboard'에 직접 추가하지 않는 동안 컨트롤을'Remove '할 수 있습니까? – Val

+0

멋진 기사 인'FillBehavior = FillBehavior.Stop'이 저에게 효과적입니다. 고맙습니다! – Val

+0

@Val 당신을 환영합니다 –