2012-12-28 125 views
0

朋友你好是新的Windows手机正在开发一个应用学习的Windows Phone 7 - 保存图像状态在独立存储

这是一个单页的应用程序与一组图像和基于Image_tap正在显示图像()它工作完美。现在我想保存图像状态(图像源)时Application_closing,我想找回状态Application_launching

MainPage.xaml.cs中文件

PhoneApplicationService phoneAppservice = PhoneApplicationService.Current;  
private void Image_Tap(object sender, GestureEventArgs e) 
    { 
     Image mybutton = (Image)sender; 
     image1.Source = mybutton.Source; 
     phoneAppservice.State["myValue"] = mybutton.Source; 
    } 

    private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e) 
    { 
     object value; 
     if (phoneAppservice.State.TryGetValue("myValue", out value)) 
     { 
      image1.Source = (System.Windows.Media.ImageSource)value; 
     } 
    } 

app.xaml.cs file:

private void Application_Launching(object sender, LaunchingEventArgs e) 
    { 
     getSource(); 
    } 

private void Application_Closing(object sender, ClosingEventArgs e) 
    { 
     saveSource(); 
    } 

private void saveSource() 
    { 
     PhoneApplicationService phoneAppservice = PhoneApplicationService.Current; 
     IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings; 

     settings["myValue"] = phoneAppservice.State["myValue"]; 
    } 

    private void getSource() 
    { 
     PhoneApplicationService phoneAppservice = PhoneApplicationService.Current; 
     IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings; 

     object myValue; 
     if(settings.TryGetValue<object>("myValue", out myValue)) 
     { 
      phoneAppservice.State["myValue"] = myValue; 
     } 
    } 

am saving the getting ima ge源,并且不能将该源设置为我的图像。我觉得我失去了一些东西或请建议花药正确的方式提前

感谢

+0

什么是'PhoneApplicationPage_Loaded'这里保存在独立存储的状态。它是MainPage的Loaded事件处理程序吗?如果是这样,在那里放置一个断点并告诉你在'value'字段中获得了什么值? – nkchandra

+0

感谢您的重播..!我只是休闲chanal9视频,适用于textBox值。现在我以前解决了这个问题,我试图在状态保存图像源,我认为这是错误的 – kartheek

+0

如果你的问题解决了,然后发布你的解决方案作为答案。 – nkchandra

回答

0

在状态我已保存的,而不是图像源的图像名称和给定后,该图像的路径中显示

MainPage.xaml.cs中文件 我已经使用单一Image_Tap事件为多个图像

private void Image_Tap(object sender, GestureEventArgs e) 
    { 
     Image mybutton = (Image)sender; // calcifying image based on image taped 
     image1.Source = mybutton.Source; // setting tapped source to image 
     phoneAppservice.State["myValue"] = mybutton.Name; // here saving the name of the image 
    } 

    private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e) 
    { 
     object value; 
     if (phoneAppservice.State.TryGetValue("myValue", out value)) 
     { 
      //retrieving the image name form state and creating new BitMapimage based on this name 
      BitmapImage newImg = new BitmapImage(new Uri("/Gallery;component/Images/"+value+".jpg", UriKind.Relative)); 
      image1.Source = newImg; 
     } 
    } 

在App.xaml.cs文件

application_closing和检索国家形式独立存储时,当应用程序启动

private void Application_Launching(object sender, LaunchingEventArgs e) 
    { 
     getSource(); 
    } 

private void Application_Closing(object sender, ClosingEventArgs e) 
    { 
     saveSource(); 
    } 

private void saveSource() 
    { 
     PhoneApplicationService phoneAppservice = PhoneApplicationService.Current; 
     IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings; 

     settings["myValue"] = phoneAppservice.State["myValue"]; //storing the state (image name) to isolated storage 

    } 

    private void getSource() 
    { 
     PhoneApplicationService phoneAppservice = PhoneApplicationService.Current; 
     IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings; 

     object myValue; 
     if(settings.TryGetValue<object>("myValue", out myValue)) 
     { 
      phoneAppservice.State["myValue"] = myValue; // saving the state from isolated storage 
     } 
    } 
相关问题