1
votes

I have a shared code, not PCL, demo project that is NOT using XAML. The content is rendered using code only. The Android project works as expected.
Im trying to work out how to connect a basic UWP project.
The UWP project has a reference to Xamarin forms

The Shared Xamarin Project, is a basic label and input field

public partial class App : Application {  // NOT XAML
    public App()  {  
         MainPage = new Demo.MainPage();
    }
    .... }

public class MainPage : ContentPage {   // NOT XAML
    Entry phoneNumberText;
    public MainPage (){
        var prompt = new Label();
        prompt.Text = "Phoneword";
        phoneNumberText = new Entry();
        var panel = new StackLayout();
        panel.Children.Add(prompt);
        panel.Children.Add(phoneNumberText);
        this.Content = panel;
    }

The Droid Project Which works

    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity   {
    protected override void OnCreate (Bundle bundle)        {
        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar; 
        base.OnCreate (bundle);
        global::Xamarin.Forms.Forms.Init (this, bundle);
        LoadApplication (new Demo.App ());
    }
}

What should I add to the UWP project to Use the Shared(not PCL) Xamarin Project.
I have looked at Xamarin docu for add UWP project to Solution But it assumes you are using XAML.

UWP CODE So far

 public App()    {
           this.Suspending += OnSuspending;
    }
    protected override void OnLaunched(LaunchActivatedEventArgs e)     {

        Frame rootFrame = Window.Current.Content as Frame;
        if (rootFrame == null)           {
            // Create a Frame to act as the navigation context and navigate to the first page
            rootFrame = new Frame();
            rootFrame.NavigationFailed += OnNavigationFailed;
            Xamarin.Forms.Forms.Init(e);

           .... Now what should I do, what is missing.


   public partial class MainPage  : Page   {
      public MainPage()     {
           LoadApplication(new Demo.App());  // LoadApplication not found...
           **?? What should i do here ???**
      }
   }
1

1 Answers

1
votes

You still need MainPage.xaml for xamarin forms to work. This page will render the xamarin forms. The xamarin forms can be in all code. This guide should help you get started.

https://developer.xamarin.com/guides/xamarin-forms/platform-features/windows/installation/universal/