Reputation: 679
I have added four images and by default i have background image. I used a button to change the background randomly. It is panorama page and i just want my app to save the last state(i.e to remember the last background image) and if my app is activated then the last image should be the default background image. Since i have already added some images to my app so i think this doesn't need Isolated Storage. What i need is if the current background image(imguri) is bg1.jpg, and if i exit the app and if i relaunch it then the default background image should be bg1.jpg. Need help!
private void BackgroundBrowser_Click(object sender, RoutedEventArgs e)
{
string imguri = "";
click_count = click_count % 5;
switch (click_count)
{
case 0: imguri = "Image/bg.jpg"; break;
case 1: imguri = "Image/bg1.jpg"; break;
case 2: imguri = "Image/bg3.jpg"; break;
case 3: imguri = "Image/bg2.jpg"; break;
case 4: imguri = ""; break;
}
click_count++;
var app = Application.Current as App;
app.appBmp = new BitmapImage(new Uri(imguri, UriKind.Relative));
ImageBrush imageBrush = new ImageBrush();
imageBrush.Stretch = Stretch.UniformToFill;
imageBrush.Opacity = 0.7;
imageBrush.ImageSource = app.appBmp;
this.LayoutRoot.Background = imageBrush;
app.appbrush = imageBrush;
app.backchanged = true;
}
Upvotes: 1
Views: 1106
Reputation: 854
All items stored in the User/Application settings need to be serializable (there is a note at the bottom of the documentation here). Learn more about serialization here.
Upvotes: 0
Reputation: 33506
You can also use System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings
in a similar manner to what DelegateX has shown. Mind that regardless of how do you 'save' your setting, it will be stored in the isolated storage space. It is just nicely wrapped and hidden as a Properties/ApplicationSettings/Session etc proeprties or class names, but in fact the data will land on ISO, and will evaporate when you uninstall the app from the device.
Upvotes: 0
Reputation: 719
You can use Application or User Settings. Go to project properties and click the Settings tab. Then create a setting name LastImagePath with String as a type:
Now just before this line:
var app = Application.Current as App;
Add this to save the path to the LastImagePath settings:
Properties.Settings.Default.LastImagePath = imguri;
Properties.Settings.Default.Save();
To load the last image, you can load up the setting wherever you want like this:
if (!(Properties.Settings.Default.LastImagePath == null))
imgpath = Properties.Settings.Default.LastImagePath;
Upvotes: 1
Reputation: 379
you need save the last image name in a file when your application exit and read image name from the file and load it when your application start again. I think this is the simplest solution.
Upvotes: 0