我有一个不使用 XAML 的共享代码,而不是 PCL,演示项目。内容仅使用代码呈现。Android 项目按预期工作。
我正在研究如何连接一个基本的 UWP 项目。
UWP 项目引用了 Xamarin 表单
所述共享项目Xamarin,是一个基本的标签和输入字段
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 文档以将 UWP 项目添加到解决方案但它假设您使用的是 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 ???**
}
}
您仍然需要 MainPage.xaml 才能使 xamarin 表单正常工作。此页面将呈现 xamarin 表单。xamarin 形式可以在所有代码中。本指南应该可以帮助您入门。
https://developer.xamarin.com/guides/xamarin-forms/platform-features/windows/installation/universal/
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句