【发布时间】: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 ???**
}
}
【问题讨论】: