Guest User

Untitled

a guest
Apr 25th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 KB | None | 0 0
  1. public partial class MainWindow : Window, INotifyPropertyChanged
  2.     {
  3.         string path;
  4.         public string Path { get { return path; } set { path = value; this.PropertyChanged(this, new PropertyChangedEventArgs("Path")); } }
  5.  
  6.         public event PropertyChangedEventHandler PropertyChanged;
  7.  
  8.         private ObservableCollection<string> imageList = new ObservableCollection<string>();
  9.         public ObservableCollection<string> ImageList
  10.         {
  11.             get { return imageList; }
  12.             set { imageList = value; PropertyChanged(this, new PropertyChangedEventArgs("ImageList")); }
  13.         }
  14.  
  15.         public MainWindow()
  16.         {
  17.             InitializeComponent();
  18.  
  19.             ImageList = new ObservableCollection<string>();
  20.  
  21.             PropertyChanged += new PropertyChangedEventHandler(MainWindow_PropertyChanged);
  22.             Path = Directory.GetCurrentDirectory() + @"\images";
  23.         }
  24.  
  25.         void MainWindow_PropertyChanged(object sender, PropertyChangedEventArgs e)
  26.         {
  27.             MethodInfo mi = this.GetType().GetMethod(e.PropertyName + "Changed");
  28.  
  29.             if (mi != null)
  30.             {
  31.                 mi.Invoke(this, new object[] { });
  32.             }
  33.         }
  34.  
  35.         public void PathChanged()
  36.         {
  37.             string[] images = Directory.GetFiles(path, "*.jpg", SearchOption.AllDirectories);
  38.  
  39.             images.ToList().ForEach(x => ImageList.Add(x));
  40.         }
  41.  
  42.         private void btnOpenDirectory_Click(object sender, RoutedEventArgs e)
  43.         {
  44.             FolderBrowserDialog dialog = new FolderBrowserDialog();
  45.  
  46.             if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  47.             {
  48.                 Path = dialog.SelectedPath;
  49.             }
  50.         }
  51.     }
Add Comment
Please, Sign In to add comment