Apply Transition effect when changing the source of an Image control

0

I have a button to which an image loaded from a ResourceDictionary is associated. In XAML I load 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;
    }
}

Is it possible to apply a "slide" transition effect when moving from one image to another?

    
asked by anonymous 31.03.2017 / 10:07

1 answer

0

You do have to do this, but it's a bit annoying.

1st Form: this is the easiest and easiest

You can create an image of the .gif format, that is, with all other images that you want to see on the slide, and finally attach it inside the C # (pirtubox, panel, form ... etc)

2nd Form: this is easy but a little extensive

Set a time for each image to run, so you will have to use the "Timer"

ex: private void changeImage (int i) {     switch (currentImage)     { // Declaration of variables together with the label that will receive the count
     int Time1, Time2 = Convert.ToInt32 (lb.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;
        }

}

If it does not work, delete the "BitmapImage".

    
31.03.2017 / 13:03