peter
peter

Reputation: 2103

Show loading animation after 1 second

How can I wait 1 second before showing a loading animation? Right now, my animation is bound to a property "IsBusy"

<mui:ModernProgressRing Grid.Column="2"  IsActive="{Binding IsBusy}" Width="140" Height="140" Style="{Binding SelectedItem.Tag, ElementName=CmbRingStyle}" />

and displayed even for fractions of a second, because IsBusy is set like this:

        BackgroundWorker worker = new BackgroundWorker();
        worker.DoWork += DoWork;
        worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
        {
             IsBusy = false;
        };
        IsBusy = true;
        worker.RunWorkerAsync();

How could I add some sort of buffer, so that IsBusy is set to true only after a small amount of time, e.g. 1 second?

Upvotes: 0

Views: 389

Answers (1)

Philip Stuyck
Philip Stuyck

Reputation: 7447

Do not do anything in your code to delay the value of IsBusy. The whole point of WPF is to have a separation between the GUI and the logic.

That being said, the trick is to do the animation in the xaml via storyboards and the like and to use 2 animations or one using key frames where it only appears as if the first second nothing is happening.

For instance suppose you want to manipulate the opacity, the first second leave the opacity untouched and after the first second then manipulate it.

Upvotes: 2

Related Questions