问题描述
我有一个关于 MVVM 模式的 Xamarin Forms 问题。它太大太多页面,无法在这里展示所有代码,但它非常紧密地基于这个项目: Xamarin.Forms MVVM: How to Work with SQLite DB
主要区别在于我有两个课程,即学期和属于这些学期的课程,因此几乎所有其他课程也都翻了一番。 Solution Explorer screenshot 但是 sqlite 似乎不允许外键,我也想不出如何自动将 TermId 发送到 Course 的 CourseTermId 字段。 (我是为学校做的,很多插件是不允许使用的,所以请不要推荐。)
您可以通过学期详细信息页面上的按钮进入添加课程页面,因此选择了正确的学期,并且添加课程是模态的,因此所选学期页面仍然可用。一切都通过数据绑定绑定,其他一切都正常工作,我所有的表单和页面。但我无法将该 TermId 连接到“课程”页面。
我可能需要一个全局变量,因为即使在运行时它应该有 Term.TermId 可用,但在我编写程序时它可能没有意识到这一点。如果是这样,我该怎么做并确保每次我选择不同的术语时都会更新它?
一旦我有了 TermId,我该如何设置 CourseTermId 以匹配它?其他一切都是通过数据绑定设置的,我不知道如何手动设置某些东西,或者等于其他东西。
//Courseviewmodel.cs is where all of the Course variables are set,from the CourseDetails.Xaml page from bindings.
public Courseviewmodel(Course course)
{
IDCourse = courseId;
courseId = course.CourseId;
courseName = course.CourseName;
courseTermId = course.CourseTermId;
….
}
private int _courseTermId;
public int courseTermId
{ get { return _courseTermId; }
set
{ SetValue(ref _courseTermId,value);
}}
//Here is some of the CoursesDetailsPage.Xaml page. It isn’t pulling the Term.TermID this far,which is why I may need the Global Variable,//or a longer pathname? I wasn't trying to set it here,just show it to see if it was coming this far. It is set automatically as the Primary Key for Term.
<TableView Intent="Form" Margin="16,0">
<TableRoot>
<TableSection Title="Course">
<EntryCell Label="Course Name" Text="{Binding Path=Course.CourseName}" />
<EntryCell Label="Course Term" Text="{Binding Path=Course.CourseTermId}" />
<EntryCell Label="Term ID" Text="{Binding Path=Term.TermId}" />
<EntryCell Label="Course ID" Text="{Binding Path=Course.CourseId}" />
….
</TableSection>
//Classes: There is more to the Course class,but that shouldn't matter.
public class Term
{
[PrimaryKey,AutoIncrement]
public int TermId { get; set; }
[MaxLength(255),Unique]
public string TermName { get; set; }
public string TermStart { get; set; }
public string TermEnd { get; set; }
public bool IsFinished { get; set; }
}
public class Course
{
[PrimaryKey,AutoIncrement]
public int CourseId { get; set; }
public int CourseTermId { get; set; }
[MaxLength(250),Unique]
public string CourseName { get; set; }
public string CourseStatus { get; set; }
...
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)