listview - Xamarin 将 ListView 绑定到静态资源可观察集合
问题描述
如何将 Itemsource 绑定到静态 Observable 集合?
Itemsource 将静态资源绑定到可观察集合
代码背后
namespace uitestmain
{
class FoodListViewModel
{
public static ObservableCollection <string> Foods { get; set; }
public string FoodName { get; set; }
public string FoodFat { get; set; }
public string FoodCarbs { get; set; }
public string FoodProtein { get; set; }
public FoodListViewModel()
{
Foods = new ObservableCollection<string>();
}
Xaml 代码
<StackLayout Spacing="20" VerticalOptions="Start" Margin="10,160,0,0">
<ListView x:Name="FoodItems" ItemsSource="{Binding Source=Foods}" CachingStrategy="RecycleElement" HeightRequest="350">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Grid.Row="1" Orientation="Horizontal" Spacing="4">
<Label Text="{Binding .}" TextColor="White" FontSize="12" FontFamily="NexaLight.otf#NexaLight"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</Grid>
解决方案
推荐阅读
- avro - AWS 上的架构注册表
- c# - XML使用c#加载重复的元素
- c# - EF 6.2 具有多个(重叠)列的唯一约束未正确生成
- wget - 如何将 bin 安装到特定文件夹?
- robotframework - 如何在运行时增加第 n 个子值?
- python - HTTPERROR 400 删除消息标签 gmail api python
- java - 如何增加 Vaadin 11.0.0 网格中的行高?
- php - 无法使用 gettext 检索 .mo 文件中的翻译字符串
- c# - 日期时间格式以编程方式 WPF Datagrid
- android - AMD 处理器上的 Android Studio 硬件加速