【问题标题】:How Add UWP project to Xamarin Solution when not using XAML不使用 XAML 时如何将 UWP 项目添加到 Xamarin 解决方案
【发布时间】:2017-09-19 08:08:14
【问题描述】:

我有一个不使用 XAML 的共享代码,而不是 PCL,演示项目。内容仅使用代码呈现。 Android 项目按预期工作。
我正在尝试研究如何连接基本的 UWP 项目。
UWP 项目有对 Xamarin 表单的引用

Shared Xamarin Project,是一个基本的标签和输入字段

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;
    }

Droid 项目有效

    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 ());
    }
}

我应该向 UWP 项目添加什么以使用共享(非 PCL)Xamarin 项目。
我看过Xamarin docu for add UWP project to Solution 但它假定您使用的是 XAML。

目前为止的 UWP 代码

 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 ???**
      }
   }

【问题讨论】:

    标签: xamarin uwp


    【解决方案1】:

    您仍然需要 MainPage.xaml 才能使 xamarin 表单工作。此页面将呈现 xamarin 表单。 xamarin 形式可以在所有代码中。本指南应该可以帮助您入门。

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

    【讨论】:

    • 经过一段时间的尝试和调查,我得出了同样的结论。我使用 A XAML shell 从头开始​​重建解决方案,并使用编码填充内容。使用 xamarin 表单的唯一/最佳方式似乎是使用 XAML,即使它显示为在没有 XAML 的情况下工作。
    猜你喜欢
    • 2015-08-29
    • 1970-01-01
    • 1970-01-01
    • 2015-11-04
    • 1970-01-01
    • 1970-01-01
    • 2017-07-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多