嗨我新與wp8我試圖開發一個應用程序。我有一些問題,從我 字典來獲得我不知道什麼是錯在這裏是我的代碼wp8字典<字符串,列表<object>>已解決
for (int i = 0; i < SharedInformation.tab.Length; i++)
{
lsCategorie.Clear();
for (int j = 0; j < SharedInformation.SharedLscitation.Count; j++)
{
if (SharedInformation.tab[i].Equals(SharedInformation.SharedLscitation[j].categorie.ToString()))
{
lsCategorie.Add(SharedInformation.SharedLscitation[j]);
}
}
SharedInformation.dic.Add(SharedInformation.tab[i], lsCategorie);
}
和我的電話
lsCitation = new List<Citation>();
lsCitation = (List<Citation>) SharedInformation.dic["amour"];
listbox.DataContext = lsCitation;
我的完整代碼
public partial class MainPage : PhoneApplicationPage
{
private Popup popup;
private BackgroundWorker backroungWorker;
ShareStatusTask quotesh = new ShareStatusTask();
SmsComposeTask quotesms = new SmsComposeTask();
List<Citation> lsCitation = new List<Citation>();
List<Citation> lsCategorie = new List<Citation>();
// Constructeur
public MainPage()
{
InitializeComponent();
ShowSplash();
}
private void ShowSplash()
{
this.popup = new Popup();
this.popup.Child = new SplashScreen();
this.popup.IsOpen = true;
StartLoadingData();
}
private void StartLoadingData()
{
backroungWorker = new BackgroundWorker();
backroungWorker.DoWork += new DoWorkEventHandler(backroungWorker_DoWork);
backroungWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backroungWorker_RunWorkerCompleted);
backroungWorker.RunWorkerAsync();
}
void backroungWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
this.Dispatcher.BeginInvoke(() =>
{
this.popup.IsOpen = false;
}
);
}
void backroungWorker_DoWork(object sender, DoWorkEventArgs e)
{
//here we can load data
Thread.Sleep(9000);
if (IsolatedStorageSettings.ApplicationSettings.Contains("data") == false)
{
InitializeComponent();
WebClient web = new WebClient();
web.DownloadStringCompleted += web_DownloadStringCompleted;
string uri = "http://quotesconsommation.azurewebsites.net/json/json.php";
web.DownloadStringAsync(new Uri(uri));
IsolatedStorageSettings.ApplicationSettings["data"] = 1;
IsolatedStorageSettings.ApplicationSettings["citation"] = lsCitation;
SharedInformation.SharedLscitation = lsCitation;
MessageBox.Show("" + NetworkInterface.GetIsNetworkAvailable() + "");
}
else
{
SharedInformation.SharedLscitation = IsolatedStorageSettings.ApplicationSettings["citation"] as List<Citation>;
}
for (int i = 0; i < SharedInformation.tab.Length; i++)
{
lsCategorie.Clear();
for (int j = 0; j < SharedInformation.SharedLscitation.Count; j++)
{
if (SharedInformation.tab[i].Equals(SharedInformation.SharedLscitation[j].categorie.ToString()))
{
lsCategorie.Add(SharedInformation.SharedLscitation[j]);
}
}
SharedInformation.dic.Add(SharedInformation.tab[i], lsCategorie);
}
}
void web_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
var rootObject = JsonConvert.DeserializeObject<RootObject>(e.Result);
foreach (var blog in rootObject.citation)
{
lsCitation.Add(blog);
}
,並在那裏我撥打電話
List<Citation> lsCitation;
public TOUTES()
{
InitializeComponent();
lsCitation = new List<Citation>();
lsCitation = (List<Citation>) SharedInformation.dic["amour"];
listbox.DataContext = lsCitation;
}
畝sharedinformation類
public static class SharedInformation
{
public static Citation Sharedcitation;
public static List<Citation> SharedLscitation;
public static Dictionary<string, List<Citation>> dic = new Dictionary<string, List<Citation>>();
public static String[] tab = { "amour", "art et spectacle", "arts et creation", "bonheur", "cinema", "cultures", "famille", "fetes", "humour", "insolite", "livres et lettres", "musique", "nature", "philosophie", "pratique", "proverbes", "sagesse", "sciences", "sport et loisirs", "theatre", "travail" };
public static bool connectionstatus;
}
究竟是什麼問題? –