我想在MainPage_Loaded
之前加载此事件处理程序WebClient wc = new WebClient();
wc.DownloadStringCompleted += new
DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
wc.DownloadStringAsync(new Uri("./ImageList.xml", UriKind.Relative));
void wc_DownloadStringCompleted(object sender,
System.Net.DownloadStringCompletedEventArgs e){.....}
答案 0 :(得分:1)
我认为这是问题 我想在加载MainPage之前“加载一些资源”“异步”!
WebClient wc = new WebClient();
wc.DownloadStringCompleted +=
new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
wc.DownloadStringAsync(new Uri("./ImageList.xml", UriKind.Relative));
void wc_DownloadStringCompleted(object sender, System.Net.DownloadStringCompletedEventArgs e){.....}
如果它是您的应用程序的主页面,那么您可以将此代码添加到Application_Startup事件处理程序中的“app.xaml.cs”。请注意,由于您是异步加载资源,因此您应该在事件处理程序中加载主页而不是Application_Startup,除非您在完成资源加载过程之前不关心主页是否已加载。