问题
In WPF
, I can easily bind a collection of image sources to a WrapPanel
with image template for instance:
<ItemsControl ItemsSource="{Binding YourChildItems}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
I cannot find an alternative Cross-platform Xamarin Forms
way of binding my Image
collection to any panel based control.
回答1:
There is an equivalent of ItemsControl
in Xamarin.Forms labs called RepeaterView
. It has support for item DataTemplate
as well as ItemsPanelTemplate. Check the wiki page on GitHub and this forum thread for examples
回答2:
- Go to here and download
WrapLayout.cs
. - Add it your project in Visual Studio.
Then you should define its namespace in xaml
xmlns:xf="clr-namespace:Xamarin.Forms"
You should use it like this code:
<ScrollView>
<xf:WrapLayout x:Name="wrp" />
</ScrollView>
- Finally you can add items in code behind.
来源:https://stackoverflow.com/questions/31969026/how-to-bind-collection-of-images-in-xamarin-forms-cross-platform