从Viewclass访问ViewModel属性

时间:2018-12-14 03:43:09

标签: xamarin xamarin.forms

enter image description here我想从Android .cs类调用内容页面类。

我使用StartActivity(new Intent(Application.Context, typeof(LoginPage)));

显示错误消息

  

“ System.ArgumentException:类型参数名称:类型不派生   从Java类型“​​

有人知道解决方案吗?请在Xamarin.Forms中帮助我。

2 个答案:

答案 0 :(得分:1)

这应该是您的App.xaml.cs类

public App()
{
  MainPage = new NavigationPage ( new MainPage());
}

MainActivity.cs文件

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
    private TextView setting;
    protected override void OnCreate(Bundle bundle)
    {       
         base.OnCreate(savedInstanceState);
         global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
         LoadApplication(new App());
         SetContentView(Resource.Layout.HomeScreen);
         setting = FindViewById<TextView>(Resource.Id.settingText);

        //check setting button is null or have value
        setting.Click += delegate
        {
            Xamarin.Forms.Application.Current.MainPage.Navigation.PushAsync(new LoginPage());
        };
    }
}

使用上面的代码并调试,以检查setting按钮是否具有实例或为null

答案 1 :(得分:0)

用LoginPage.Class或LoginPage :: Class.java(kotlin)替换typeof(LoginPage)

相关问题