【问题标题】:How to bind collection of images in Xamarin Forms Cross-Platform如何在 Xamarin Forms Cross-Platform 中绑定图像集合
【发布时间】:2015-11-05 06:54:00
【问题描述】:
在WPF 中,我可以使用图像模板轻松地将一组图像源绑定到WrapPanel:
<ItemsControl ItemsSource="{Binding YourChildItems}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
我找不到将我的Image 集合绑定到任何基于面板的控件的替代Cross-platform Xamarin Forms 方式。
【问题讨论】:
标签:
c#
wpf
xaml
binding
xamarin-forms
【解决方案1】:
在 Xamarin.Forms 实验室中有一个等效的 ItemsControl,称为 RepeaterView。它支持项目DataTemplate 以及ItemsPanelTemplate。查看 GitHub 上的 wiki page 和此 forum thread 以获取示例
【解决方案2】:
-
到这里下载WrapLayout.cs。
-
在 Visual Studio 中将其添加到您的项目中。
-
那么你应该在 xaml 中定义它的命名空间
xmlns:xf="clr-namespace:Xamarin.Forms"
-
你应该像这样使用它:
<ScrollView>
<xf:WrapLayout x:Name="wrp" />
</ScrollView>
- 终于可以在代码后面添加项目了。