Apply transition effect when changing the source of an Image control

Asked

Viewed 203 times

0

I have a button to which is associated an image loaded from a Resourcedictionary. In XAML I carry them like this:

<Button x:Name="selecao" Grid.Row="1" Grid.Column="2" Margin="10" Click="selecao_Click">
    <Image x:Name="img" Source = "{StaticResource inverno}"/>
</Button>

In code-Behind I change it like this:

private void mudarImagem(int i)
{
    switch (currentImage)
    {
        case 0: img.Source = (BitmapImage)Application.Current.Resources["inverno"]; break;
        case 1: img.Source = (BitmapImage)Application.Current.Resources["primavera"]; break;
        case 2: img.Source = (BitmapImage)Application.Current.Resources["verao"]; break;
        case 3: img.Source = (BitmapImage)Application.Current.Resources["outono"]; break;
    }
}

It is possible to apply a "slide" transition effect when moving from one image to the other?

1 answer

0

You can do that, but it’s a bit boring.

1st Form: this is the easiest and simplest

You can create a separate image of the format. gif, this is with all other images you want to be viewed on the slide, and finally attach inside the c# (pirtubox,panel,form ...etc)

2nd form: this is easy but a little extensive

Set a time for each image when running, so you will need to use the "Timer"

ex: private void mudarImage(int i) { switch (currentImage) { //Declaration of variables together with the label that will receive the count
int Time1, Time2 = Convert.Toint32(lbContagem.Text);

        Tempo1 = Tempo2 + 1; //Inicialização da contagem
        lbContagem.Text = Convert.ToString(Tempo1); //Label que esta a receber a contagem

        if (Tempo1 == 1)
        {
             img.Source =BitmapImage.Current.Resources["inverno"]
        }
        if (Tempo1 == 3)
        {
             img.Source =BitmapImage.Current.Resources["primavera"]; break;
        }
        if (Tempo1 == 5)
        {
             img.Source =BitmapImage.Application.Current.Resources["verao"];
        }
        if (Tempo1 == 7)
        {
            img.Source =BitmapImage.Application.Current.Resources["outono"]; 
        }
            timer1.Enabled = false;
          return;
        }

}

test if it doesn’t work out delete the "Bitmapimage".

  • I don’t know if I explained myself!

  • I know how to change the image ... but I want it to come with transitional effects.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.