[英]How to navigate to a different content page after a function is called
我有一個應用程序,它在 Xamarin forms(iOS 端)中有 2 個選項卡。 我想知道在調用 function 后如何讓我的應用導航到不同的內容頁面。 讓我告訴你我在代碼中的意思:
這些是我的內容頁面中的兩個功能:
protected override async void OnAppearing()
{
base.OnAppearing();
TakePhotoButton_Clicked();
}
async void TakePhotoButton_Clicked()
{
if (App.pictureTaken) return;
App.pictureTaken = true;
//Allows users to take pictures in the app
if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
{
DisplayAlert("No Camera", "Camera is not available.", "OK");
return;
}
var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
{
//Sets the properties of the photo file
SaveToAlbum = true,
PhotoSize = PhotoSize.MaxWidthHeight,
DefaultCamera = CameraDevice.Rear
});
if (file == null)
return;
}
調用 TakePhotoButton_Clicked() 后,我想強制我的應用導航到我的其他內容頁面。
在偽代碼中它看起來像:
NavigateTo(MyOtherContentPage);
但我不確定這將如何工作,或者是否存在類似的東西。 有什么建議么?
歡迎來到 SO!
如果MainPage的Root page為NavigationPage ,如: MainPage = new NavigationPage (new Page1Xaml ());
,您可以使用Navigation.PushAsync
導航到另一個頁面,如下所示:
async void OnNextPageButtonClicked (object sender, EventArgs e)
{
await Navigation.PushAsync (new Page2Xaml ());
}
否則,如果Root 頁面是普通頁面,您可以使用 model 導航方法導航到另一個頁面,如下所示:
async void OnItemSelected (object sender, SelectedItemChangedEventArgs e)
{
...
await Navigation.PushModalAsync (detailPage);
}
}
更多信息可以參考Performing Navigation and Pushing Pages to the Modal Stack 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.