using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms;
using System.IO;

namespace WpfApplication3
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private FolderBrowserDialog folderBrowserSelectedImageDialog = null;
        private List<FileInfo> imagesList = null; 
        public MainWindow()
        {
            imagesList=new List<FileInfo>();
            folderBrowserSelectedImageDialog=new FolderBrowserDialog();
            InitializeComponent();
        }

        private void OpenFolder_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                if (folderBrowserSelectedImageDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    DirectoryInfo directoryInfo=new DirectoryInfo(folderBrowserSelectedImageDialog.SelectedPath);
                    imagesList =
                        directoryInfo.GetFiles("*.png")
                            .Union(directoryInfo.GetFiles("*.jpg"))
                            .Union(directoryInfo.GetFiles("*.gif"))
                            .Union(directoryInfo.GetFiles("*.bmp"))
                            .ToList();
                    if (imagesList.Count > 0)
                    {
                        SliderImage.Maximum = imagesList.Count-1;
                        SliderImage.Value = 0;
                        SliderImage_OnValueChanged(SliderImage, null);

                    }
                }

            }
            catch (Exception ex)
            {
                ShowMessage(ex.Message);
            }
        }

        private void BtnPrev_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                SliderImage.Value --;
            }
            catch (Exception ex)
            {
                ShowMessage(ex.Message);
            }
        }

        private void BtnNext_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                SliderImage.Value ++;
            }
            catch (Exception ex)
            {
                ShowMessage(ex.Message);
            }
        }

        private void ShowMessage(string emessage)
        {
            System.Windows.MessageBox.Show(emessage);
        }

        private void SliderImage_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            try
            {
                if (imagesList.Count > 0)
                {
                    ImagePlase.Source=new BitmapImage(new Uri(imagesList[(int)SliderImage.Value].FullName,UriKind.Absolute));
                }
            }
            catch (Exception ex)
            {
                ShowMessage(ex.Message);
            }
        }
    }
}
