C# Xamarin中的XAML ListView不起作用

C# Xamarin中的XAML ListView不起作用,c#,sqlite,xaml,listview,xamarin,C#,Sqlite,Xaml,Listview,Xamarin,我开始学习Xamarin,我正在尝试创建第一个测试项目。我创建了ListView,它显示BindingContext中的ObservableCollection。“Take”是一个具有三个属性的表。问题是,当我在emulator上运行应用程序时,会出现以下eror对话框:“进程系统没有响应。是否要关闭它?” 但如果我删除标记和所有内部XAML代码,一切都会正常工作,但我想在ListView的每个元素中显示类“Take”的属性值 <?xml version="1.0" encoding="u

我开始学习Xamarin,我正在尝试创建第一个测试项目。我创建了ListView,它显示BindingContext中的ObservableCollection。“Take”是一个具有三个属性的表。问题是,当我在emulator上运行应用程序时,会出现以下eror对话框:“进程系统没有响应。是否要关闭它?”
但如果我删除标记和所有内部XAML代码,一切都会正常工作,但我想在ListView的每个元素中显示类“Take”的属性值

<?xml version="1.0" encoding="utf-8" ?>

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="App1.Views.Page1">

<ContentPage.Content>
    <StackLayout>
        <Label Text="Welcome to my first project"></Label>
        <Label Text="Why does it does not work?"></Label>
        <ListView ItemsSource="{Binding GetList}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <TextCell Text="{Binding Word}"></TextCell>
                    <Button Text="SomeText"></Button>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
</ContentPage.Content>
</ContentPage>

尝试将
文本单元格
按钮
放在
堆栈布局
中或任何类型的布局放在
元素中:

<ListView ItemsSource="{Binding GetList}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <StackLayout>
                    <TextCell Text="{Binding Word}"></TextCell>
                    <Button Text="SomeText"></Button>
                </StackLayout>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>


DataTemplate
元素的子元素必须属于或派生自类型
ViewCell

您不能将
TextCell
和其他内容组合在一起,在您的情况下是
按钮
。如果要同时显示文本和按钮,则需要使用自定义单元格

这是使用基类
ViewCell
完成的,在基类中定义要显示的布局

<StackLayout>
    <Label Text="Welcome to my first project"></Label>
    <Label Text="Why does it does not work?"></Label>
    <ListView ItemsSource="{Binding GetList}">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <StackLayout>
                        <Label Text="{Binding Word}"></Label>
                        <Button Text="SomeText"></Button>
                    </StackLayout>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</StackLayout>


希望这有帮助。

尝试从数据模板中删除该按钮
<ListView ItemsSource="{Binding GetList}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <StackLayout>
                    <TextCell Text="{Binding Word}"></TextCell>
                    <Button Text="SomeText"></Button>
                </StackLayout>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>
<StackLayout>
    <Label Text="Welcome to my first project"></Label>
    <Label Text="Why does it does not work?"></Label>
    <ListView ItemsSource="{Binding GetList}">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <StackLayout>
                        <Label Text="{Binding Word}"></Label>
                        <Button Text="SomeText"></Button>
                    </StackLayout>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</StackLayout>