我正在构建简单的 WP8 应用程序。我正在尝试ListPicker
使用作为另一个类成员的集合来更新控件。此类通过异步调用获取此数据。当收到响应触发 MainPage 上更新ListPicker
.
public void coinUtil_ReceivedPriceEvent(object sender, EventArgs e)
{
PopulateListPicker();
}
public void PopulateListPicker()
{
try
{
foreach (KeyValuePair<string, double> item in coinUtil.cointPriceList)
{
listPickerCurrencies.Items.Add(item.Key);
}
}
catch (UnauthorizedAccessException ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
我收到以下异常:
System.Windows.ni.dll 中出现“System.UnauthorizedAccessException”类型的第一次机会异常
System.Windows.ni.dll 中发生了“System.UnauthorizedAccessException”类型的异常,并且在托管/本机边界 System.UnauthorizedAccessException:无效的跨线程访问之前未处理。在 MS.Internal.XcpImports.CheckThread() 在 System.Windows.DependencyObject.GetValueInternal(DependencyProperty dp) 在 System.Windows.FrameworkElement.GetValueInternal(DependencyProperty dp) 在 System.Windows.Controls.ItemsControl.get_Items() 在 BitCoinTail.MainPage .PopulateListPicker()
奇怪的是,当我尝试用一个简单的字符串访问这个类的另一个成员时,它工作正常。我在 WP7 中进行了一些开发,但不记得曾经遇到过这个异常。谁能看到我做错了什么?