android - CarouselView CarouselPage 如何使用数据库中的绑定项创建集合页面?没有 MVVM
问题描述
我是 Xamarin 的新手,我有这门课的数据库
[Table("Version")]
public class Version
{
[PrimaryKey,AutoIncrement,Column("_Id")]
public int Version_ID { get; set; }
public string Version_Name { get; set; }
[ForeignKey(typeof(Profile))]
public int Version_ProfileID { get; set; }
[ForeignKey(typeof(Version))]
public int Version_ParentID { get; set; }
[OneToMany(CascadeOperations = CascadeOperation.All)]
public List<ParameterValue> Version_ParameterValue { get; set; }
}
我想在没有 MVVM 的情况下,类中的 1 个项目已成为 Carousel 中的 1 页。(这不是主屏幕)这就是我所有的 XAML:
CarouselPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="Versions"
x:Name="LayoutVersions"
ItemsSource="{Binding}">
<CarouselPage.ItemTemplate>
<DataTemplate>
<Label Text="{Binding Version_Name}"></Label>
</DataTemplate>
</CarouselPage.ItemTemplate>
</CarouselPage>
和 xaml.cs:
public Versions(Categories Category)
{
selectedCategory = Category;
ItemsSource = App.Database7.GetItems(); // it`s line not worked, how to create new page with binding item from database?
InitializeComponent();
}
版本库.cs:
public IEnumerable<Version> GetItems()
{
return database.GetAllWithChildren<Version>(recursive: true);
}
新 XAML:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="SniperNote.ListParameters"
x:Name="LayoutVersions">
<ContentPage.Content>
<CarouselView x:Name="CarouselVersion">
<CarouselView.ItemTemplate>
<DataTemplate>
<Label Text="{Binding Version_Name}"></Label>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
新的 XAML.cs:
public ListParameters(Categories Category)
{
InitializeComponent();
selectedCategory = Category;
CarouselVersion.ItemsSource = App.Database7.GetItems();
}
PS对不起我的英语,谢谢你的回答。
解决方案
推荐阅读
- python - 从单独的数据框 pandas 中的最近时间戳中提取信息
- go - 在 Go 中解析多个模板
- node.js - 如何通过nodejs中的代理服务器测试网站的速度
- laravel - 为 Laravel 迁移设置默认值
- ios - Firebase 电话身份验证
- python - 如何使用 statsmodels 获得多元线性回归的标准化(Beta)系数
- php - Magento 1.9 cron 作业未运行
- aem - SQL2 查询在路径中搜索当前路径(在路径字段或 RTE 中定义)
- c# - Is it possible to reference a resource within a resource?
- java - Java HashMap'key'对象是通过引用存储的?