0

I wanted to know how I could make a button to load a window that allows me to upload 3 images, so giving the impression of a gif.

If I do a single project everything is fine, but when I do I associate a button does not work for me. Why is that? Can someone help me understand?

This code XAML:

<Image Name="ConnectionImage" Grid.RowSpan="2" Grid.ColumnSpan="2">
            <Image.Triggers>
                <EventTrigger RoutedEvent="Image.Loaded">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Name="DoubleAnimation_ConnectionTest" Storyboard.TargetName="ConnectionImage" 
                                             Storyboard.TargetProperty="Width" From="200" To="200" 
                                             Duration="0:0:1.0"  Completed="DoubleAnimation_Completed"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Image.Triggers>
        </Image>

while the code of image is:

    int ctr = 1;
    private void DoubleAnimation_Completed (object sender, EventArgs e)
    {
        ShowImage();
        DoubleAnimation_ConnectionTest.BeginAnimation(Image.WidthProperty, DoubleAnimation_ConnectionTest);
    }

    private void ShowImage()
    {
        string filename = "Images/Connection" + ctr + ".jpg";
        BitmapImage image = new BitmapImage();
        image.BeginInit();
        image.UriSource = new Uri(filename, UriKind.Relative);
        image.EndInit();
        ConnectionImage.Source = image;

        ctr++;

        if (ctr > 3)
        {
            ctr = 1;
        }
    }

and button:

 private void Button_Test_DB_Click(object sender, RoutedEventArgs e)
        {
            Window_Test Test_DB = new Window_Test();
            Test_DB.Show();

        }
iamwill
  • 11
  • 6
  • "does not work for me" is not really a useful problem description. Please be more specific about that. And a note: using an animation's Completed event for cyclic execution of some code looks really strange. Why not just use a DispatcherTimer? – Clemens Jul 24 '14 at 07:32
  • If I do a project with only the animation in a window then it works, otherwise button retrieved from the window, I get out a window empty. – iamwill Jul 24 '14 at 07:56

1 Answers1

0

That is entirely possible using C#. You can use the FrameDimension Class to help you. Unfortunately, I can't close this question for being a duplicate because there are no accepted answers to these posts... instead, I can only recommend that you see the answers to the How do I get an animated gif to work in WPF? and Animating Gif in WPF questions here on Stack Overflow.

Additionally, you could also see the The Code - An Animated GIF Class page from the Visual C# Kicks website.

Community
  • 1
  • 1
Sheridan
  • 68,826
  • 24
  • 143
  • 183
  • Thanks, but it really is not a gif, but a series of animated images that make the design because they are in sequence. – iamwill Jul 24 '14 at 08:01