In the ListPicker
in my Windows Phone Application there is a List of items which a user can select one or more items and view those selected items.
Until this point everything goes fine after this point I want to save the selected items on the same page. Now what happens when I close the application and starts it again there is no selected items saved. So my question is how can I save the changes made by the user? I don't want to save them in a separate file in the isolated storage actually. Thanks in advance.
Here is the XAML code:
<Border x:Name="Border"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<UserControl x:Name="UserControl">
<StackPanel>
<TextBlock x:Name="MultipleSelectionModeSummary" Margin="8 8 0 8" TextWrapping="Wrap" Width="300" HorizontalAlignment="Left"/>
<Canvas x:Name="ItemsPresenterHost" MinHeight="46">
<ItemsPresenter x:Name="ItemsPresenter">
<ItemsPresenter.RenderTransform>
<TranslateTransform x:Name="ItemsPresenterTranslateTransform"/>
</ItemsPresenter.RenderTransform>
</ItemsPresenter>
</Canvas>
</StackPanel>
</UserControl>
</Border>
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ScrollViewer Grid.Row="1">
<toolkit:ListPicker Header="Print in colors"
SelectionMode="Multiple"
FullModeHeader="Colors"
CacheMode="BitMapCache"
x:Name="PrintInColors"
Template="{StaticResource ListPickerControlTemplate1}">
<sys:String>Cyan</sys:String>
<sys:String>Magenta</sys:String>
<sys:String>Yellow</sys:String>
<sys:String>Black</sys:String>
<sys:String>White</sys:String>
<sys:String>Blue</sys:String>
<sys:String>Orange</sys:String>
<sys:String>Gray</sys:String>
<sys:String>Silver</sys:String>
</toolkit:ListPicker>
</ScrollViewer>
</Grid>
Here is the CS code:
private string Summarize(System.Collections.IList items)
{
string str = "";
if (null != items)
{
if (items.Contains("Cyan"))
{
str += "Cyan";
}
if (items.Contains("Magenta"))
{
str += "Mangeta";
}
if (items.Contains("Yellow"))
{
str += "Yellow";
}
if (items.Contains("Black"))
{
str += "Black";
}
if (items.Contains("White"))
{
str += "White";
}
if (items.Contains("Blue"))
{
str += "Blue";
}
if (items.Contains("Orange"))
{
str += "Orange";
}
if (items.Contains("Gray"))
{
str += "Gray";
}
if (items.Contains("Silver"))
{
str += "Silver";
}
}
return str;
}
Please rethink. You need persistent storage to achieve that. Your application is installed and never get changed. I mean, all changes user made are in memory (RAM) and it will be unloaded/removed soon after the application closed.
Isolated storage is the most commonly used persistent storage for this purpose. And it is relatively simple as far as I can see (compared to saving to local or online database), so you really should consider saving the data to isolated storage.