【发布时间】:2018-04-11 09:49:32
【问题描述】:
我正在开发一个 Xamarin Forms 应用程序,该应用程序需要一个带有 CustomCells 'MyCustomCell' 的 ListView。单元格具有中等数量的绑定 (9),并且每个单元格都非常相似,因此我决定将缓存策略设置为 RecycleElement。此列表可以轻松包含 100 个项目。每个单元格包含两个带有 Uri 源的图像。
我通常在 MyCustomCell.xaml 中绑定视图的属性,例如使用图像:
<Image
x:Name="MyImage"
Source="{Binding ImageSource}"
.../>
但我最近阅读了这篇文章 https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/listview/performance,我想知道 MyCustomCell.xaml 中的绑定与像这样的覆盖方法“OnBindingContextChanged”中的主要区别是什么:
protected override void OnBindingContextChanged()
{
base.OnBindingContextChanged();
var item = BindingContext as MyModel;
MyImage.Source = ImageSource.FromUri(item.ImageSource);
}
我测试了这两种解决方案,第二个对我来说似乎更快。我对吗 ?这两种解决方案的真正区别是什么?
【问题讨论】:
标签: c# xamarin binding xamarin.forms custom-cell