Загрузка данных


using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;

namespace WpfApplication3
{
    public partial class MainWindow : Window
    {
        private class DogBreed
        {
            public string Name { get; set; }
            public string ImagePath { get; set; }
        }

        private List<DogBreed> gallery = new List<DogBreed>();
        private int currentIndex = 0;

        private bool isDragging = false;
        private Point startPoint;

        public MainWindow()
        {
            InitializeComponent();
            LoadGallery();
            UpdateCard();
        }

        private void LoadGallery()
        {
            gallery.Add(new DogBreed { Name = "Пудель", ImagePath = "Image/347756718380326.jpeg" });
            gallery.Add(new DogBreed { Name = "Корги", ImagePath = "Image/46.jpg" });
            gallery.Add(new DogBreed { Name = "Охотничья", ImagePath = "Image/AQAOZG1kJugAltxkaemgp1-tdpuF_QXe2cXeJjb1GklXjjFAWvbEy11ars_Y1Hnm0H4Fw_L-MtwhmFiBHgyOJMzmGU8.jpg" });
            gallery.Add(new DogBreed { Name = "Длинная", ImagePath = "Image/levretka_2_1.jpg" });
            gallery.Add(new DogBreed { Name = "Длинная 2", ImagePath = "Image/dc41b24fe426fe5fbea827d4498223841b73fb52.jpg" });
        }

        private void UpdateCard()
        {
            if (gallery.Count == 0) return;

            TxtBreedName.Text = gallery[currentIndex].Name;
            
            Uri uri = new Uri($"pack://application:,,,/{gallery[currentIndex].ImagePath}");
            ImgDog.Source = new BitmapImage(uri);
        }

        private void OnSwipeStart(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                isDragging = true;
                startPoint = e.GetPosition(this);
                ((UIElement)sender).CaptureMouse();
            }
        }

        private void OnSwipeMove(object sender, MouseEventArgs e)
        {
            if (!isDragging) return;

            Point currentPoint = e.GetPosition(this);
            double deltaX = currentPoint.X - startPoint.X;
            
            ImgTransform.X = deltaX;
        }

        private void OnSwipeEnd(object sender, MouseButtonEventArgs e)
        {
            if (!isDragging) return;

            isDragging = false;
            ((UIElement)sender).ReleaseMouseCapture();

            Point endPoint = e.GetPosition(this);
            double deltaX = endPoint.X - startPoint.X;
            double threshold = 70; 

            if (deltaX < -threshold)
            {
                SwipeTo(next: true);
            }
            else if (deltaX > threshold)
            {
                SwipeTo(next: false);
            }
            else
            {
                AnimateReturn();
            }
        }

        private void SwipeTo(bool next)
        {
            double exitX = next ? -Width : Width;

            DoubleAnimation exitAnimation = new DoubleAnimation
            {
                To = exitX,
                Duration = TimeSpan.FromMilliseconds(150)
            };

            exitAnimation.Completed += (s, e) =>
            {
                if (next)
                {
                    currentIndex = (currentIndex + 1) % gallery.Count;
                }
                else
                {
                    currentIndex = (currentIndex - 1 + gallery.Count) % gallery.Count;
                }

                UpdateCard();

                ImgTransform.X = next ? Width : -Width;

                DoubleAnimation enterAnimation = new DoubleAnimation
                {
                    To = 0,
                    Duration = TimeSpan.FromMilliseconds(200),
                    EasingFunction = new QuadraticEase { EasingMode = EasingMode.EaseOut }
                };
                ImgTransform.BeginAnimation(TranslateTransform.XProperty, enterAnimation);
            };

            ImgTransform.BeginAnimation(TranslateTransform.XProperty, exitAnimation);
        }
            
        private void AnimateReturn()
        {
            DoubleAnimation returnAnimation = new DoubleAnimation
            {
                To = 0,
                Duration = TimeSpan.FromMilliseconds(150),
                EasingFunction = new QuadraticEase { EasingMode = EasingMode.EaseOut }
            };
            ImgTransform.BeginAnimation(TranslateTransform.XProperty, returnAnimation);
        }
    }
}