Windows Phone 7中的图像库 [英] Image Gallery in windows phone 7

查看:51
本文介绍了Windows Phone 7中的图像库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  public   partial   class  MainPage:PhoneApplicationPage 
{
private List< string> images = new List< string>();

private int imageIndex = 0 ;

public MainPage()
{
InitializeComponent();
已加载+ = RoutedEventHandler(MainPage_Loaded);
}

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

私有 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;
}
}


受保护 覆盖 void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base .OnNavigatedTo(E);
}

受保护 覆盖 void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
base .OnNavigatedFrom(e);
}

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

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





我在WINDOWS PHONE7制作图库,下一个图像按钮是工作,但代码为,最后图像按钮不起作用。任何代码???告诉我

解决方案

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


这篇关于Windows Phone 7中的图像库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆