How to navigate from android project acvtivity page to class library project xaml page in VS2017 ?

saivignasaivigna Member ✭✭

Hi,
I have a solution in VS2017 having two projects ,class library,android project how to navigate from android project activity page login method to xaml page in class library project

protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);

btnsign = FindViewById(Resource.Id.btnlogin);
btnsign.Click += Btnsign_Click;
CreateDB();
}

private void Btnsign_Click(object sender, EventArgs e)
{
try
{
string dpPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "abc.db3");
var db = new SQLiteConnection(dpPath);
var data = db.Table();
var data1 = data.Where(x => x.username == txtname.Text && x.password == txtPwd.Text).FirstOrDefault();
if (data1 != null)
{
Toast.MakeText(this, "Login Success", ToastLength.Short).Show();

        // How to navigate from here to 'side menu xaml page' in class library project
            }
     }
}

Answers

  • yelinzhyelinzh Member, Xamarin Team Xamurai

    Do you mean that navigate from 'xamarin.android' to 'xamarin.forms'?

  • saivignasaivigna Member ✭✭

    Hi ,
    Thanks for reply.yes i want to navigate from 'xamarin.android' to 'xamarin.forms'

  • saivignasaivigna Member ✭✭

    hi please find the attached image.Thanks

  • yelinzhyelinzh Member, Xamarin Team Xamurai

    In Xamarin_.Android MainActiviity.cs

    LoadApplication(new App()); //Click the App and you'll find it jump into App.xaml
    

    The method will jump app.xaml and automaticlly navigate from 'xamarin.android' to 'xamarin.forms'. The MainActivity.cs just likes a container which contains app.xaml and page.xaml. Add the code to achieve the feature you want and deploy on the platform like android.

    Xamarin.Forms exposes a complete cross-platform UI toolkit for .NET developers. Build fully native Android, iOS, and Universal Windows Platform apps using C# in Visual Studio.
    You can refer to https://docs.microsoft.com/zh-cn/xamarin/get-started/quickstarts/deepdive?pivots=windows

  • saivignasaivigna Member ✭✭

    private void Btnsign_Click(object sender, EventArgs e)
    {
    try
    {
    string dpPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "abc.db3");
    var db = new SQLiteConnection(dpPath);
    var data = db.Table();
    var data1 = data.Where(x => x.username == txtusername.Text && x.password == txtPassword.Text).FirstOrDefault();
    if (data1 != null)
    {
    Toast.MakeText(this, "Login Success", ToastLength.Short).Show();
    LoadApplication(new App());
    }
    else
    {
    Toast.MakeText(this, "Username or Password invalid", ToastLength.Short).Show();
    }
    }
    catch (Exception ex)
    {
    Toast.MakeText(this, ex.ToString(), ToastLength.Short).Show();
    }
    }
    Hi i am trying above code to sign in but getting error at "LoadApplication(new App())"

    error: {System.InvalidOperationException: You MUST call Xamarin.Forms.Init(); prior to using it.

  • yelinzhyelinzh Member, Xamarin Team Xamurai

    Which class is the code in? Could you post the screenshot of the complete code?

  • saivignasaivigna Member ✭✭

    Hi, pls find the attached file which contains mainactivity.cs and app.xaml code.TQU

  • yelinzhyelinzh Member, Xamarin Team Xamurai

    Write the code in app.xaml and app.xaml.cs instead of xamarin.android.
    You can refer to the forms demo. https://developer.xamarin.com/samples/xamarin-forms/BoxView/BasicBoxView/

  • saivignasaivigna Member ✭✭

    Hi , how to change contentpage to masterdetailpage when i tried i am getting error TQ U

    public partial class LoginXAM : ContentPage------> MasterDetailPage
    {
    public LoginXAM()
    {
    InitializeComponent();
    Init();
    }

        void Init()
        {}
    

    }

  • yelinzhyelinzh Member, Xamarin Team Xamurai
    edited March 19

    MasterDetailPage is used to manage two related pages of information.

    Refer to https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/master-detail-page

Sign In or Register to comment.