WPF C# Tutorial – Make a simple image gallery in visual studio
- Subject: WPF C# Tutorials
- Learning Time: 1 hour
This is a simple project and please double check the full code below to make sure you have followed it correctly.
Full Source Code –
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 |
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; namespace image_gallery { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { int i = 1; // this integer will start with a 1 public MainWindow() { InitializeComponent(); } private void goNext(object sender, RoutedEventArgs e) { i++; // increase i by 1 // if i's value gets larger than 6 then reset i back to 1 if (i > 6) { i = 1; } // change the picture according to the i's value picHolder.Source = new BitmapImage(new Uri(@"pics/" + i + ".jpg", UriKind.Relative)); } private void goBack(object sender, RoutedEventArgs e) { i--; // this will decrease 1 from i // if the value of i is less than 1 // then give i the value of 6 if (i < 1) { i = 6; } // change the picture according to the i's value picHolder.Source = new BitmapImage(new Uri(@"pics/" + i + ".jpg", UriKind.Relative)); } } } |
Hey bro thank you so much . You saved my life and my school life.