Click here to Skip to main content
15,880,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
public partial class MainPage : PhoneApplicationPage
  {
      private List<string> images = new List<string>();

      private int imageIndex = 0;

      public MainPage()
      {
          InitializeComponent();
          Loaded += new RoutedEventHandler(MainPage_Loaded);
      }

      void MainPage_Loaded(object sender, RoutedEventArgs e)
      {
          LoadImages();
          ShowNextImage();
          ShowlastImage();
      }

      private void LoadImages()
      {
          images.Add("/images/boot.jpg");
          images.Add("/images/canadian_dinosaur.jpg");
          images.Add("/images/cassette.jpg");
          images.Add("/images/computer_nerd_inside.jpg");
      }

      private void ShowNextImage()
      {
          var bi = new BitmapImage(new Uri(images[imageIndex], UriKind.Relative));
          myImg.Source = bi;
          imageIndex = (imageIndex + 1) % images.Count;
      }

      private void ShowlastImage()
      {
          if (imageIndex <= 0)
          {
              var bi = new BitmapImage(new Uri(images[imageIndex], UriKind.Relative));
              myImg.Source = bi;
              imageIndex = (imageIndex - 1) % images.Count;
          }
      }


      protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
      {
          base.OnNavigatedTo(e);
      }

      protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
      {
          base.OnNavigatedFrom(e);
      }

      private void Next_Click(object sender, RoutedEventArgs e)
      {
          ShowNextImage();
      }

      private void back_Click(object sender, RoutedEventArgs e)
      {
          ShowlastImage();
      }
  }


I Am making image gallery in WINDOWS PHONE7,NEXT IMAGE button is working but THE CODE FOR,LAST IMAGE button is not working.any code???tell me
Posted
Comments
ridoy 20-Aug-12 2:30am    
You mean back_Click not working?..do you get any error or it did nothing after click?
gaurav273 20-Aug-12 2:49am    
thank you,,very much i hace solved it

1 solution

C#
private void ShowNextImage()
      {
          try
          {
              if (imageIndex == 5)
              {
                  imageIndex = 1%1-1;
              }
              var bi = new BitmapImage(new Uri(images[imageIndex + 1], UriKind.Relative));
              myImg.Source = bi;
              imageIndex = (imageIndex + 1) % images.Count;
          }
          catch
          {
          }
      }
      private void ShowlastImage()
      {
          try
          {
              if (imageIndex == 0)
              {
                  imageIndex = 6;
              }
              var bi = new BitmapImage(new Uri(images[imageIndex - 1], UriKind.Relative));
              myImg.Source = bi;
              imageIndex = imageIndex - 1;
          }
          catch
          {
          }
      }
 
Share this answer
 
v2
Comments
ridoy 20-Aug-12 3:34am    
good solution..my 5
Siddhanath Jadhav 31-Jan-14 8:08am    
Hi,Gurav,you have any memory issue,i.s,If you swipe images memory increase or not,Because I have working windows phone8 app.Here i have use Bitmaplist to collect camera roll images and pass to pivot control(pvtimages.Itemsource=camimages()) at the time of application launch and after i have use "Next""Previous"button to swipe images one by one Its working fine But when swiping images memory increases 2-3mb per swiping images.To solve memory issue i have lots of try but still pending use Gc.Collect(), Gc.PendingFinalizars(), DecodePixelWidth,Destructor for class but still memory increases ,If you have any solve these issue then please provide simple code for these..Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900