我正在使用contentPage上的按钮创建应用,当我点击该按钮时,它将移动到新的contentPage。但它遇到了一些问题。 我使用sqlite数据库 连接很好。
这是模型类
public class entries
{
public entries()
{
}
public entries(string word)
{
this.word = word;
}
public entries(string word, string wordtype, string definition)
{
this.word = word;
this.type = wordtype;
this.defn = definition;
}
public string word
{ get; set; }
public string type
{ get; set; }
public string sdex { get; set; }
public int wlen { get; set; }
public string defn
{ get; set; }
}
MainPage.xaml.cs中的按钮
public partial class MainPage : ContentPage
{
public string word;
public MainPage()
{
InitializeComponent();
}
//this is the button
async void AllWordButton_Clicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new AllWordPage());
}
}
这是AllWordPage.xaml.cs
public partial class OrtherAppPage : ContentPage
{
private SQLiteConnection conn;
public entries entry;
public OrtherAppPage()
{
InitializeComponent();
conn = DependencyService.Get<ISQLite>().GetConnection();
var data = (from word in conn.Table<entries>() select word);
DataList.ItemsSource = data;
}
}
这是AllWordPage.xaml
<ContentPage.Content>
<StackLayout Orientation="Horizontal" HorizontalOptions="Center">
<Label Text="This is Other App Page" />
</StackLayout>
<StackLayout>
<ListView x:Name="DataList">
<ListView.ItemTemplate>
<TextCell Text="{Binding Word}"></TextCell>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage.Content>
当我点击按钮时。得到这个通知: 您的应用已进入中断状态,但没有要显示的代码,因为所有线程都在执行外部代码(通常是系统或框架代码)。
我怎样才能显示这个问题。请帮忙。非常感谢你
答案 0 :(得分:1)
共享代码中存在一些问题:
ContentPage
只能包含一个孩子。 AllWordPage.xaml
包含2 StackLayouts
。这将在运行时抛出异常。entries
,应将其命名为Entries
。Entries
应使用Table("Entries")
属性进行修饰。Id
列,因此可以识别单个行。还有一些其他列可能会有所帮助,例如CreatedAt
,DeletedAt
,RowVersion
等。SQLiteConnection
应该被处置。async
方法不阻止UI线程 - (from word in conn.Table<entries>() select word)
- &gt; conn.Table<entries>().ToListAsync()
EntityFramework
。P.S。:Official documentation包含良好的代码示例和解释。从那里开始。