Xamarin.forms Xamarin形成SQLiteNetExtensions数据绑定

Xamarin.forms Xamarin形成SQLiteNetExtensions数据绑定,xamarin.forms,Xamarin.forms,我试图在配方页面中显示配料对象列表 我有两张桌子 public class Ingredients { // primary key [PrimaryKey, AutoIncrement] public int IngredientsId { get; set; } // specify the foreign key [ForeignKey(typeof(Recipe))] public int RecipeId { get; set; }

我试图在配方页面中显示配料对象列表

我有两张桌子

 public class Ingredients
{
    // primary key
    [PrimaryKey, AutoIncrement]
    public int IngredientsId { get; set; }

    // specify the foreign key
    [ForeignKey(typeof(Recipe))]
    public int RecipeId { get; set; }

    // many to one relationship with recipe
    [ManyToOne]
    public Recipe Recipe { get; set; }

    // other attributes
    public string IngredientsName { get; set; }
    public double Ammount { get; set; }
    public string Units { get; set; }

    public override string ToString()
    {
        return IngredientsName + "      " + Ammount + Units;
    }
}
配方

    public class Recipe
{
    [PrimaryKey, AutoIncrement]
    public int RecipeID { get; set; }
    public string RecipeName { get; set; }
    public string VideoURL { get; set; }
    public string PrepTime { get; set; }
    public string CookTime { get; set; }
    public int Serves { get; set; }
    public string MealType { get; set; }
    public string Equipment { get; set; }
    public string Method { get; set; }

    // one to many relationship with ingredients 
    [OneToMany(CascadeOperations = CascadeOperation.All)]
    public List<Ingredients> Ingredients { get; set; }

}
公共类配方
{
[主密钥,自动增量]
public int RecipeID{get;set;}
公共字符串RecipeName{get;set;}
公共字符串VideoURL{get;set;}
公共字符串预处理时间{get;set;}
公共字符串CookTime{get;set;}
公共int服务{get;set;}
公共字符串MealType{get;set;}
公共字符串设备{get;set;}
公共字符串方法{get;set;}
//与配料的一对多关系
[OneToMany(级联操作=级联操作.All)]
公共列表成分{get;set;}
}
他们都是双向的,我通过调试知道这一点。我现在尝试使用数据绑定在列表视图中显示包含所有成分的配方页面

<?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:video="clr-namespace:SQLiteListView.FormsVideoLibrary"
             xmlns:local="clr-namespace:SQLiteListView.Models"
             x:Class="SQLiteListView.Views.ItemPage"
             Title="{Binding RecipeName}">
    <ContentPage.Content>
        <ScrollView>
            <StackLayout>
                <Label Text="{Binding RecipeName}"
                       FontSize="50"/>
                <video:VideoPlayer HeightRequest="320" WidthRequest="220">
                    <video:VideoPlayer.Source>
                        <video:ResourceVideoSource>
                            <video:ResourceVideoSource.Path>
                                <OnPlatform x:TypeArguments="x:String">
                                    <On Platform="iOS" Value="Videos/iOSApiVideo.mp4" />
                                    <On Platform="Android" Value="ScrambledEggs.mp4" />
                                    <On Platform="UWP" Value="Videos/UWPApiVideo.mp4" />
                                </OnPlatform>
                            </video:ResourceVideoSource.Path>
                        </video:ResourceVideoSource>
                    </video:VideoPlayer.Source>
                </video:VideoPlayer>

                <Label 
                    Margin="10"
                    Text="Meal Type"
                    FontSize="Large" 
                    FontAttributes="Bold"/>
                <Label Text="{Binding MealType}"
                       Margin="10"
                       FontSize="Medium"/>

                <Label Margin="10"
                       Text="Serves" 
                       FontSize="Large" 
                       FontAttributes="Bold"/>
                <Label Text="{Binding Serves}" 
                       Margin="10"
                       FontSize="Medium"/>

                <Label Margin="10"
                       Text="Preperation Time" 
                       FontSize="Large" 
                       FontAttributes="Bold"/>
                <Label Text="{Binding PrepTime}" 
                       Margin="10"
                       FontSize="Medium"/>

                <Label Margin="10"
                       Text="Cooking Time" 
                       FontSize="Large" 
                       FontAttributes="Bold"/>
                <Label Text="{Binding CookTime}"  
                       Margin="10"
                       FontSize="Medium"/>

                <Label Margin="10"
                       Text="Equipment" 
                       FontSize="Large"
                       FontAttributes="Bold"/>
                <Label Text="{Binding Equipment}" 
                       Margin="10"
                       FontSize="Medium"/>

                <Label Margin="10"
                       Text="Ingredients" 
                       FontSize="Large" 
                       FontAttributes="Bold"/>

                <ListView x:Name="IngredientsListView" ItemsSource ="Ingredients">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <StackLayout>
                                <Label Text="{Binding IngredientName }"/>
                                <Label Text="{Binding Ammount}"/>
                                <Label Text="{Binding Units}"/>
                            </StackLayout>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>

                <Label Margin="10"
                       Text="Method" 
                       FontSize="Large" 
                       FontAttributes="Bold"/>
                <Label Text="{Binding Method}"  
                       Margin="10"
                       FontSize="Medium"/>

            </StackLayout>
        </ScrollView>
    </ContentPage.Content>
</ContentPage>

我试着从一个统计员那里得到配料,但我不能仅仅得到配方上的配料。我尝试将Recipe.Components作为ItemSource添加到ListView中,但这似乎也不起作用


有人能帮忙吗?

指定您的
滚动视图中未显示的内容和正在显示的内容。另外,
成分
是否有多个元素?另外,我会将所有的
成分
放入
可观察列表视图
,然后将新实例绑定到
项目资源
Hi Greggz,感谢您的回复。除配料外,所有内容都显示在ScrollView中。每个配方中有不同数量的成分,显示的每种成分都应该在一行中有名称、数量和单位。我尝试将所有成分放入一个可观察的集合中并从那里绑定,但似乎不起作用。请给堆栈布局一个
高度要求的
。还可以尝试向Listview提供另一组项目,以确保问题不是来自成分。如果必须,请修改viewcells