Splash Screen Attenuation

I am trying to make a fade effect on my splash screen in a WPF application. The opacity of the image object is initially 0. This code will change the opacity from 0 (min) to 1 (max.), But the img_waves.Opacity line just doesn't work. Image transparency remains 0.

private void Splash_ContentRendered(object sender, EventArgs e)
    {
        System.Threading.Thread.Sleep(3000);
        for (double x = 0; x<=1; x+=0.01d)
        { 
            System.Threading.Thread.Sleep(15);
            //MessageBox.Show(x.ToString());
            img_waves.Opacity = x;
        }
        this.Close();
    }

But if I activate the string 'MessageBox.Show (x.ToString ()); as you can see in this image:Code is working

The code works, but I have to keep clicking on the posts.

My question is why? Why doesn’t work without MessageBox.Show?

+4
source share
2 answers

So far, I agree with @Luaan's explanation of why, as an alternative solution for your loop, you can use Storyboardc DoubleAnimationon a Opacityproperty

private void Splash_ContentRendered(object sender, EventArgs e)
{
    var sb = new Storyboard();
    var da = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromSeconds(1.5)));
    da.BeginTime = TimeSpan.FromSeconds(3);
    Storyboard.SetTargetProperty(da, new PropertyPath("Opacity"));
    Storyboard.SetTarget(da, img_waves);
    sb.Children.Add(da);
    sb.Completed += (s1, e1) => this.Close();
    sb.Begin();
}
+1

. . , , .

:

private async void Splash_ContentRendered(object sender, EventArgs e)
{
    await Task.Delay(3000);

    for (double x = 0; x<=1; x+=0.01d)
    { 
        await Task.Delay(15);

        img_waves.Opacity = x;
    }

    this.Close();
}

, , . , "" . , , - :)

, .

, , WPF - ? WPF, ? MSDN.

+3

All Articles