[英]How to navigate one Content page to another Content page from client project (IOS/Android) in xamarin forms?
[英]Xamarin how to open xamarin forms page from android project?
我想從Xamarin Android項目打開Xamarin表單頁面。 在android項目中,我創建了太棒項目圖像,我在這里調用事件從Xamarin表單項目打開頁面。
這是我的MainActivity.cs toolabar圖像項實現:
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
private IMenu CurrentMenu { get; set; }
private ImageView imgSmallC { get; set; }
public override bool OnCreateOptionsMenu(IMenu menu)
{
ActionBar.DisplayOptions = ActionBarDisplayOptions.HomeAsUp | ActionBarDisplayOptions.ShowCustom | ActionBarDisplayOptions.ShowTitle | ActionBarDisplayOptions.ShowHome;
LayoutInflater inflater = (LayoutInflater)ActionBar.ThemedContext.GetSystemService(LayoutInflaterService);
View customActionBarView = inflater.Inflate(Resource.Layout.actionbar_custom_view_done, null);
imgSmallC = (ImageView)customActionBarView.FindViewById<ImageView>(Resource.Id.ImgSmallC);
imgSmallC.Click += (object sender, EventArgs args) =>
{
StartActivity(typeof(MyPopupPage));
};
return base.OnCreateOptionsMenu(menu);
}
}
在StartActivity中,我從Xamarin表單項目調用MyPopupPage.xaml頁面,但不幸的是,當我調試項目時,我點擊工具欄圖像時出現這樣的錯誤:
System.ArgumentException:type參數名稱:Type不是從java類型派生的。
你不能使用基於Xamarin.Form
的Page
作為Android Activity
,它們是兩個完全不同的東西 。
您可以從Xamarin.Android
項目訪問Xamarin.Forms
Application
單例並將其用於PushModelAsync
或PushAsync
await Xamarin.Forms.Application.Current.MainPage.Navigation.PushModalAsync(new PushPageFromNative.MyPage());
Dependency Service
的示例: 接口:
using System;
namespace PushPageFromNative
{
public interface IShowForm
{
void PushPage();
}
}
基於Xamarin.Form
的代碼:
var pushFormBtn = new Button
{
Text = "Push Form",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
};
pushFormBtn.Clicked += (sender, e) =>
{
DependencyService.Get<IShowForm>().PushPage();
};
Xamarin.Android
Dependancy實施:
async public void PushPage()
{
// Do some Android specific things... and then push a new Forms' Page
await Xamarin.Forms.Application.Current.MainPage.Navigation.PushModalAsync(new PushPageFromNative.MyPage());
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.