-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrintsViewModel.cs
54 lines (46 loc) · 1.7 KB
/
PrintsViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using ReactiveUI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Input;
namespace ThreeByTwoPrints
{
public class PrintsViewModel : ReactiveObject
{
private readonly List<PhotoViewModel> photos = new List<PhotoViewModel>();
private PhotoViewModel selectedPhoto;
private readonly ICollectionView collectionView;
private readonly ReactiveCommand<object> openPhotosCommand;
public PrintsViewModel()
{
collectionView = CollectionViewSource.GetDefaultView(photos);
openPhotosCommand = ReactiveCommand.Create();
openPhotosCommand.Subscribe(_ => OpenPhotos());
}
private void OpenPhotos()
{
var dialog = new Microsoft.Win32.OpenFileDialog();
dialog.Filter = "Photos|*.jpg;*.jpeg|All Files|*.*";
dialog.DefaultExt = ".jpg";
dialog.Title = "Open Photos";
dialog.Multiselect = true;
if (dialog.ShowDialog() == true)
{
var newFilePaths = dialog.FileNames.Except(photos.Select(p => p.FilePath));
photos.AddRange(newFilePaths.Select(p => new PhotoViewModel(p)));
collectionView.Refresh();
}
}
public ICollectionView Photos { get { return collectionView; } }
public PhotoViewModel SelectedPhoto
{
get { return selectedPhoto; }
set { this.RaiseAndSetIfChanged(ref selectedPhoto, value); }
}
public ICommand OpenPhotosCommand { get { return openPhotosCommand; } }
}
}