【发布时间】:2023-04-09 15:37:03
【问题描述】:
如何在 Home GridView 中显示来自 SQlite 数据库的数据,在 DisplayDetails() 方法中使用 ItemsSource 传递数据时,错误说 Grid 不包含 ItemsSource 的定义并且没有可访问的扩展方法,接受“网格”类型的参数。
请查找Home.xaml 网格布局和Home.xaml.cs 类了解更多详情
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="soccerapp.Home" BackgroundColor="White" Title="Home">
<ContentPage.Content>
<Grid x:Name="gridDisplay" Padding="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Use Grid.Column to specify column -->
<Label Grid.Row="0" Grid.Column="0" Text="{Binding FullName}" BackgroundColor="#92f459"/>
<Label x:Name="HomeLabel" Text="Home Page is here" TextColor="White"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" FontSize="Small"></Label>
</Grid>
</ContentPage.Content>
</ContentPage>
下面是Home.xaml.cs
namespace soccerapp
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Home : ContentPage
{
public SQLiteConnection conn = null;
public PlayerDetails playermodel;
public Home(string parameter1)
{
InitializeComponent();
HomeLabel.Text = parameter1;
conn = DependencyService.Get<Isqlite>().GetConnection();
conn.CreateTable<PlayerDetails>();
DisplayDetails();
}
public void DisplayDetails()
{
var details = (from x in conn.Table<PlayerDetails>() select x).ToList();
gridDisplay.ItemsSource= details;
}
}
我已经添加了PlayerDetails 模型类:
namespace soccerapp
{
public class PlayerDetails
{
[PrimaryKey, AutoIncrement]
public int id { get; set; }
public string FullName { get; set; }
public string Mobile { get; set; }
public string SoccerPosition { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public string ConfirmPassword { get; set; }
}
}
【问题讨论】:
标签: xamarin xamarin.forms