【发布时间】:2013-12-04 21:16:00
【问题描述】:
我们正在开发一个 Windows Phone 应用程序 (CurrencyExchange),并且有一个包含文本框和列表框的页面。 ListBox 的 itemsource 是它的 viewmodel 的可观察集合的属性类型。文本框的 textchange 事件正在更改可观察集合的所有项目,但是当可观察更改并尝试绑定列表框的项目时,页面被锁定。我看到了一个名为 Fastobservablecollection 的自定义可观察集合,它没有在 viewmodel 中运行,因为它使用了不能在 viewmodel 中使用的 DispatcherObject 和 Dispatcherprioty。有没有比 ObservableCollection 更好的替代方案?
List<Currency> newList = new List<Currency>(CurrencyConversions.ToList());
foreach (var item in newList)
{
Double result;
if (Double.TryParse(AmountPhone, NumberStyles.Any, new System.Globalization.CultureInfo("tr-TR"), out result))
item.CalculatedValue = Math.Round(result * (Direction == "0" ? item.ConversionRateSell : item.ConversionRateBuy), 2);
else
item.CalculatedValue = 0;
}
CurrencyConversions = new ObservableCollection<Currency>(newList);
或
List<Currency> newList = new List<Currency>();
foreach (var item in CurrencyConversions)
{
Double result;
if (Double.TryParse(AmountPhone, NumberStyles.Any, new System.Globalization.CultureInfo("tr-TR"), out result))
item.CalculatedValue = Math.Round(result * (Direction == "0" ? item.ConversionRateSell : item.ConversionRateBuy), 2);
else
item.CalculatedValue = 0;
newList.Add(item);
}
CurrencyConversions = new ObservableCollection<Currency>(newList);
谢谢。
使用智能收集
List<Currency> newList = new List<Currency>(CurrencyConversions.ToList());
foreach (var item in newList)
{
Double result;
if (Double.TryParse(Amount, NumberStyles.Any, new System.Globalization.CultureInfo("tr-TR"), out result))
item.CalculatedValue =Math.Round( result * (Direction == "0" ? item.ConversionRateSell : item.ConversionRateBuy),2);
else
item.CalculatedValue = 0;
}
CurrencyConversions = new SmartCollection<Currency>(newList);
【问题讨论】:
-
请添加一些代码以及如何更新集合
-
你也可以看看this问题,如果它为你提供了有用的信息
-
我已经添加了代码,现在正在尝试您的建议
-
我试过了,但没有任何变化,仍然很慢。也许我用错了。我已经写了最后一个有问题的代码,你能检查一下吗?
-
类型
Currency是如何实现的?
标签: xaml mvvm binding windows-phone observablecollection