How to bind collection of images in Xamarin Forms Cross-Platform

旧时模样 提交于 2019-12-08 08:24:23

问题


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:


  1. Go to here and download WrapLayout.cs.
  2. Add it your project in Visual Studio.
  3. Then you should define its namespace in xaml

    xmlns:xf="clr-namespace:Xamarin.Forms"

  4. You should use it like this code:

<ScrollView>
     <xf:WrapLayout x:Name="wrp" />   
</ScrollView>
  1. Finally you can add items in code behind.


来源:https://stackoverflow.com/questions/31969026/how-to-bind-collection-of-images-in-xamarin-forms-cross-platform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!