加载一系列具有WPF c#移动效果的图像

本文关键字:图像 移动 一系列 WPF 加载 | 更新日期: 2023-09-27 18:14:26

我想知道如何制作一个按钮来加载一个允许我上传3张图像的窗口,从而给人一种gif的印象。

如果我做一个项目,一切都很好,但是当我做的时候,我关联一个按钮不适合我。为什么呢?有人能帮我理解吗?

代码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>

,而图像的代码为:

    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;
        }
    }

按钮:

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

加载一系列具有WPF c#移动效果的图像

使用c#完全可以实现。您可以使用FrameDimension类来帮助您。不幸的是,我不能因为这个问题是重复的而关闭这个问题,因为这些帖子没有被接受的答案…相反,我只能建议您查看如何在WPF中获得动画gif的答案?和在WPF中动画Gif在这里堆栈溢出问题。

另外,你还可以从Visual c# Kicks网站看到the Code - An Animated GIF Class页面。