-
Notifications
You must be signed in to change notification settings - Fork 0
/
folderOfImagesWindow.xaml.cs
119 lines (103 loc) · 3.66 KB
/
folderOfImagesWindow.xaml.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using System;
using System.Collections.Generic;
using System.IO;
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.Shapes;
namespace cseNoticeBoard
{
/// <summary>
/// Interaction logic for folderOfImagesWindow.xaml
/// </summary>
public partial class folderOfImagesWindow : Window
{
public string imageFolder;
int numberOfFiles;
int imageNumber;
string[] filesInFolder;
public folderOfImagesWindow()
{
InitializeComponent();
imageFolder = variables.currentSubDirectorySelected + "//";
filesInFolder = Directory.GetFiles(variables.currentSubDirectorySelected);
numberOfFiles = filesInFolder.Length;
imageNumber = 5;
try
{
display();
}
catch (IndexOutOfRangeException)
{
notificationsWindow notificationsWindow = new notificationsWindow();
notificationsWindow.textBlockMessage.Text = "Oops! No images in this Folder!";
notificationsWindow.Show();
// this was causing the problem in the following scenario
// 1) open empty folder 2) go out of range 3) control is retained normally but not going to main screen
// 1) open empty folder 2) open another folder 3) control not retained and not going to main screen
//variables.currentWindow = variables.previousCurrentWindow;
this.Close();
}
}
public void display()
{
keepImageNumberInsideRange();
string imagePath = imageFolder + System.IO.Path.GetFileName( filesInFolder[imageNumber] );
try
{
var uri = new Uri(imagePath);
// if the image is found (name is correct)
var bitmap = new BitmapImage(uri);
image.Source = bitmap;
}
catch (FileNotFoundException)
{
notificationsWindow notificationsWindow = new notificationsWindow();
notificationsWindow.textBlockMessage.Text = "Oops! No images in this Folder!";
notificationsWindow.Show();
variables.currentWindow = variables.previousCurrentWindow;
this.Close();
}
catch (IndexOutOfRangeException)
{
notificationsWindow notificationsWindow = new notificationsWindow();
notificationsWindow.textBlockMessage.Text = "Oops! No images in this Folder!";
notificationsWindow.Show();
variables.currentWindow = variables.previousCurrentWindow;
this.Close();
}
}
public void keepImageNumberInsideRange()
{
if (imageNumber>= numberOfFiles)
{
imageNumber = 0;
}
else if (imageNumber < 0)
{
imageNumber = numberOfFiles - 1;
}
}
private void buttonNext_Click(object sender, RoutedEventArgs e)
{
imageNumber += 1;
display();
}
private void buttonPrevious_Click(object sender, RoutedEventArgs e)
{
imageNumber -= 1;
display();
}
private void buttonGoBack_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}