且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Windows Phone 7中的图像库

更新时间:2023-01-24 15:25:21

  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()
{
试用
{
if (imageIndex == 0
{
imageIndex = 6 ;
}
var bi = new BitmapImage( new Uri(images [imageIndex - 1 ],UriKind.Relative));
myImg.Source = bi;
imageIndex = imageIndex - 1 ;
}
catch
{
}
}


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

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
          {
          }
      }