你好朋友我是 Windows 手机的新手正在开发一款用于学习的应用程序
这是一个带有一组图像的单页应用程序,并且正在基于Image_tap()显示图像,它运行良好。现在我想在Application_closure时保存图像状态(图像源)并且我想检索状态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文件中:
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;
}
}
我正在保存获取图像源,但无法将该源设置为我的图像。我想我遗漏了一些东西,或者请提出正确的方法
提前致谢