Sto provando a fare un semplice test con Storage isolato in modo da poterlo utilizzare per un'applicazione Windows Phone 7 che sto facendo.Simple Isolated Storage Problema
Il test che sto creando imposta a crea una chiave e un valore con un pulsante e con l'altro pulsante imposta tale valore uguale al testo di TextBlock.
namespace IsoStore
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
public class AppSettings
{
IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
private void button1_Click(object sender, RoutedEventArgs e)
{
appSettings.Add("email", "[email protected]");
}
private void button2_Click(object sender, RoutedEventArgs e)
{
textBlock1.Text = (string)appSettings["email"];
}
}
}
}
In questo modo mi dà questo errore:
Impossibile accedere a un membro non statica di tipo esterno 'IsoStore.MainPage' via tipo annidato 'IsoStore.MainPage.AppSettings'
così ho provato questo:
namespace IsoStore
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
public class AppSettings
{
IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
private void button1_Click(object sender, RoutedEventArgs e)
{
appSettings.Add("email", "[email protected]");
}
}
private void button2_Click(object sender, RoutedEventArgs e)
{
textBlock1.Text = (string)appSettings["email"];
}
}
}
E invece ottengo questo errore:
Il nome 'app ettings 'non esiste nel contesto attuale
Quindi quale ovvio problema sto trascurando qui?
Grazie mille per il vostro tempo.
Quindi non ho nemmeno bisogno di creare l'istanza "appSettings" di IsolatedStorage? Ci sarebbe un vantaggio se lo facessi? – Dan
@ No non proprio. Potresti discutere di leggibilità, ma è piuttosto sottile. –
Bene, grazie ancora per tutto il vostro aiuto. – Dan