In WPF, after the DoubleAnimation UIElement property cannot be changed?

OK, I create a graphical interface for my MP3 player using WPF, and I have a border that increases its width for every second of the track being played, thereby creating a "Progress Bar" for the current song. I called the border ProgressBarBorder. After the entire playlist is complete, I wanted to use DoubleAnimation to fade the border. Now, if I start the player again, the border reacts as expected (the width value starts from 0 and continues until the end of the song), but the opacity property remains 0.0 for some strange reason (this is the value that DoubleAnimation sets). I explicitly coded

ProgressBarBorder.Opacity = 1.0;

in a method that starts playback. However, it remains invisible. Now, if I do not use DoubleAnimation and just write

ProgressBarBorder.Opacity = 0.0; 

when the playlist is completed, it returns to 1.0 again when I start the player again. It is for this reason that I am sure that the animation is causing the problem. Also, shouldn't the property return to its original state after the animation is complete? If so, my border should become visible automatically after the animation finishes.

Here is my partially pseudo code:

if (TrackIsComplete)
{
    DoubleAnimation Fading = new DoubleAnimation();
    Fading.From = 1.0;
    Fading.To = 0.0;
    Fading.Duration = TimeSpan.FromSeconds(3);
    ProgressBarBorder.BeginAnimation(Border.OpacityProperty, Fading);
}

and

private void PlayTrack()
{
    ProgressBarBorder.Opacity = 1.0;
    Play();
    ....
}

Can anyone help? Thanks.

+3
source share
3 answers

. , BeginAnimation :

private void PlayTrack()
{
    ProgressBarBorder.BeginAnimation(Border.OpacityProperty, null);
    ProgressBarBorder.Opacity = 1.0;
    ....
}
+6

, . , , , . , , .

+4

Play with the FillBevior of your animation timeline. This may help: http://msdn.microsoft.com/en-us/library/system.windows.media.animation.fillbehavior.aspx

0
source

Source: https://habr.com/ru/post/1709922/


All Articles