我在Xamarin表單導航中遇到問題,因爲它根本不起作用。Xamarin表單導航
我的代碼:
appname.cs
using System;
using Xamarin.Forms;
namespace List
{
public class App : Application {
public App() {
MainPage = new NavigationPage (new HomePage());
}
}
}
homepage.xaml.cs
using System;
using Xamarin.Forms;
using System.ComponentModel;
using System.Globalization;
namespace List
{
public partial class HomePage : ContentPage {
public HomePage() {
InitializeComponent();
}
public void OnButtonClicked (object sender, EventArgs args) {
Navigation.PushAsync (new DetailsPage());
}
}
}
我的目的顯然是要打開主頁面,有一個按鈕在那裏按一下就進入第二頁。 但是出現這種情況,而不是每當按鈕被點擊:
錯誤信息
Could not load type 'UIKit.UIView_UITextField' from assembly 'Xamarin.Forms.Platform.iOS'.
有人能告訴我,我做錯了什麼嗎?
編輯 - 爲DetailsPage代碼,因爲這可能是錯誤的來源:
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace List
{
public partial class DetailsPage : ContentPage
{
public DetailsPage()
{
InitializeComponent();
}
}
}
編輯2 - 爲XAML頁面代碼(感謝大家的幫助,我真的很感激):
首頁的.xaml
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:List" x:Class="List.HomePage">
<ContentPage.Title>
1
</ContentPage.Title>
<Button Text="Click Me!" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" Clicked="OnButtonClicked" />
</ContentPage>
DetailsPage.Xaml:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="List.DetailsPage">
<Label Text="LOL"/>
</ContentPage>
聽起來好像您的DetailsPage有問題。您的導航代碼是正確的。 – Jason
我注意到你正在使用Xaml。你能不能請張貼你的Xaml,因爲這看起來是錯誤的根源。 –
我會檢查你的iOS項目上安裝了Xamarin Forms nuget包以及你的Forms項目。 –