[英]Specified cast is not valid exception in FreshMvvm Xamarin
我正在使用FreshMvvm,在应用程序启动时遇到异常。
未处理的异常:System.InvalidCastException:指定的强制转换无效。 :at(包装动态方法)System.Object.7(intptr,intptr,intptr):[错误]致命的异常例外:System.InvalidCastException:指定的强制转换无效。
public App()
{
InitializeComponent();
var mainPage = FreshPageModelResolver.ResolvePageModel<StudentListPageModel>(); //Here getting exception
MainPage = new FreshNavigationContainer(mainPage);
}
StudentListPage.xaml
<StackLayout>
<Label Text="{Binding StudentName}" Font="20"/>
<Label Text="{Binding StudentClass}" Font="20"/>
<Label Text="{Binding City}" HorizontalOptions="FillAndExpand"/>
</StackLayout>
StudentListPageModel.cs
public class StudentListPageModel : FreshBasePageModel
{
private Student _student;
public StudentListPageModel()
{
_student = new Student();
}
public string StudentName
{
get { return _student.StudentName; }
set
{
_student.StudentName = value;
RaisePropertyChanged("StudentName");
}
}
public string StudentClass
{
get { return _student.StudentClass; }
set
{
_student.StudentClass = value;
RaisePropertyChanged("StudentClass");
}
}
public string City
{
get { return _student.City; }
set
{
_student.City = value;
RaisePropertyChanged("City");
}
}
}
Student.cs
public class Student
{
public string StudentName { get; set; }
public string StudentClass { get; set; }
public string City { get; set; }
}
StudentListPage.xaml.cs文件为空
public partial class StudentListPage : ContentView
{
public StudentListPage ()
{
InitializeComponent ();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.