-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhotoViewModel.cs
More file actions
44 lines (36 loc) · 1.36 KB
/
PhotoViewModel.cs
File metadata and controls
44 lines (36 loc) · 1.36 KB
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
using ReactiveUI;
using System;
using System.Reactive.Linq;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace ThreeByTwoPrints
{
public class PhotoViewModel : ReactiveObject
{
private Lazy<BitmapImage> image;
private readonly string filePath;
private int copies;
private readonly ReactiveCommand<object> addCopyCommand;
private readonly ReactiveCommand<object> removeCopyCommand;
public PhotoViewModel(string filePath)
{
this.filePath = filePath;
copies = 1;
image = new Lazy<BitmapImage>(() => new BitmapImage(new Uri(filePath)));
addCopyCommand = ReactiveCommand.Create();
addCopyCommand.Subscribe(_ => Copies = Copies + 1);
removeCopyCommand = ReactiveCommand.Create();
removeCopyCommand.Subscribe(_ => Copies = Math.Max(1, Copies - 1));
}
public string FilePath { get { return filePath; } }
public ImageSource Image { get { return image.Value; } }
public int Copies
{
get { return copies; }
set { this.RaiseAndSetIfChanged(ref copies, value); }
}
public ICommand AddCopyCommand { get { return addCopyCommand; } }
public ICommand RemoveCopyCommand { get { return removeCopyCommand; } }
}
}