WPF按钮gif动画

WPF按钮gif动画,wpf,animation,Wpf,Animation,我正在尝试实现一个登录按钮,该按钮将更改为请稍候。。。模式一旦按下。我在考虑一些内置按钮的故事板动画或GIF图像动画。似乎我是WPF的新手,在几次搜索尝试后,我无法找到一个完全有效的想法 登录按钮想法 做上述事情的最佳方式是什么?有没有办法消除GIF图像,并使用一些路径或类似的方法创建相同的图像?还请注意,我希望按钮的这种行为在按钮上触发。单击事件。只需从visual studio工具->NuGet Package Manager->Package Manager控制台添加WpfAnimate

我正在尝试实现一个登录按钮,该按钮将更改为请稍候。。。模式一旦按下。我在考虑一些内置按钮的故事板动画或GIF图像动画。似乎我是WPF的新手,在几次搜索尝试后,我无法找到一个完全有效的想法

登录按钮想法


做上述事情的最佳方式是什么?有没有办法消除GIF图像,并使用一些路径或类似的方法创建相同的图像?还请注意,我希望按钮的这种行为在按钮上触发。单击事件。

只需从visual studio
工具->NuGet Package Manager->Package Manager控制台添加
WpfAnimatedGif
在那里,您可以找到Package adder窗口,几秒钟后键入
pm>安装Package WpfAnimatedGif.
应添加包。现在,首先添加
名称空间
xmlns:gif=”http://wpfanimatedgif.codeplex.com“
然后设计您的
按钮。

 <Window x:Class="WpfApplication1.MainWindow" Name="root"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:gif="http://wpfanimatedgif.codeplex.com"
            Width="500" Height="500" DataContext="{Binding ElementName=root}">

        <StackPanel>
            <Button Name="BtnLogin" Width="100" Height="30" Content="Login" Background="Red" Margin="0,0,0,5" Click="Button_Click"/>
            <Button  Width="100" Height="30" Background="Red">
            <Grid>
                    <Image  gif:ImageBehavior.AnimatedSource="{Binding DataContext.LoadingImage}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
                <TextBlock Text="Please Wait" Padding="30,0,0,0" HorizontalAlignment="Right" VerticalAlignment="Center"/>
            </Grid>
        </Button>
        </StackPanel>
       </Window>

上面的代码将始终显示gif。我只想点击事件。@Anup您能指出您是如何解决它的吗?我对它感兴趣。请分享你的解决方案。Thx.@user1624552如回答中所述,我遵循了相同的步骤,即WpfAnimateGif nuget包。请注意,我没有选择更改按钮文本。相反,我在一个单独的控件中显示了动画gif和文本。没有第三方库,只需一个静态图像和
RotateTransform
story board,您就可以轻松完成。点击激活,但多久?最后我用第三方GIF插件。
public partial class MainWindow : Window,INotifyPropertyChanged
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private ImageSource _LoadingImage;
        public ImageSource LoadingImage 
        {
            get { return _LoadingImage; }
            set 
            {
                _LoadingImage = value;
                OnPropertyChanged("LoadingImage");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            LoadingImage = GetBitmapImage("/aaaa.gif");
        }
        public static BitmapImage GetBitmapImage(String location)
        {
            BitmapImage image = null;
            try
            {
                Uri iconUri = new Uri("pack://application:,,,/" + ";component" + location, UriKind.RelativeOrAbsolute);

                image = new BitmapImage(iconUri);
            }
            catch (Exception ex)
            {
            }
            return image;
        }
    }