[英]Xamarin - How to Bind Data From Rest API to a StackLayout NOT ListView
[英]How to bind data to stacklayout in xamarin
这是我尝试的代码:
<ScrollView x:Name="newArrival" Orientation="Horizontal" HorizontalScrollBarVisibility="Always">
<StackLayout Orientation="Horizontal">
<Frame BackgroundColor="Black" HeightRequest="100" WidthRequest="100">
<StackLayout>
<Image HeightRequest="70"/>
<Label Text="{Binding Name}" FontSize="15" HorizontalOptions="Center"/>
<Label Text="{Binding Desc}" FontSize="13" HorizontalOptions="Center"/>
</StackLayout>
</Frame>
</StackLayout>
</ScrollView>
感谢您的帮助。
根据您的Image,您只想通过ScrollView
实现,如果在此视图中有很多Items是不合理的。 我建议您通过以下三种方法来实现。
如果您想了解有关三种方法的更多详细信息,可以参考此链接。 https://causerexception.com/2018/02/06/xamarin-forms-ultimate-horizontal-list-guide/
有上面的演示代码。
https://github.com/DanielCauser/XamarinHorizontalList
如果您对Model-View-ViewModel(MVVM)的数据绑定有疑问,请参阅此链接。 https://blog.xamarin.com/introduction-to-data-binding/
您可以使用水平的ScrollView
并在内部提供一个Stacklayout
,它也是水平的。 在后面的代码中,您可以通过创建一个循环来动态创建元素,该循环遍历列表与要绑定的对象。 每当有新对象通过循环时,都会在Stacklayout
内部创建一个新元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.