[英]Xamarin ToolBarItems Navigation rules
我正在嘗試將這些工具欄添加到我的內容頁面,如果它是navigaitionstack的第一頁,則可以使用。 但是,如果我將其用作第二個菜單,則無法獲得任何菜單。 如何使工具欄項目出現在IssuePage上而不將其作為起始頁面?
public partial class IssuesPage : ContentPage
{
var home = new ToolbarItem
{
Text = "Add New",
Icon = "Add.png",
Order = ToolbarItemOrder.Primary,
Priority = 0,
};
home.Clicked += this.OnClickNewIssue;
this.ToolbarItems.Add(home);
var map = new ToolbarItem
{
Text = "Map",
Icon = "map.png",
Order = ToolbarItemOrder.Primary,
Priority = 0,
};
map.Clicked += this.OnClickShowMap;
this.ToolbarItems.Add(map);
var loginLocation = new ToolbarItem
{
Text = "Login and Location",
Icon = "menu.png",
Order = ToolbarItemOrder.Secondary,
Priority = 0,
};
loginLocation.Clicked += this.OnClickLoginLocation;
this.ToolbarItems.Add(loginLocation);
var filter = new ToolbarItem
{
Text = "Filter and Sorting",
Icon = "filter.png",
Order = ToolbarItemOrder.Secondary,
Priority = 1,
};
filter.Clicked += this.OnClickSetFilter;
this.ToolbarItems.Add(filter);
}
這是稍后的頁面順序。
public App()
{
Client = new AppIssueClient();
// The root page of your application
MainPage = GetMainPage();
}
public static Page GetMainPage()
{
return new NavigationPage(new IssueCarouselPage(new UIIssueVM(true)));
}
這就是我從IssueCarosuelPage轉到IssuePage的方式
void OnGoToEventList(object sender, EventArgs args)
{
Navigation.PushModalAsync(new IssuesPage(-1));
}
原因是使用PushModalAsync
您將一個全新的頁面推PushModalAsync
堆棧上,該頁面不僅替換了IssueCarouselPage
,而且替換了包裝它的NavigationPage
。 因此,您將失去工具欄功能。 要解決此問題,請執行以下操作:
void OnGoToEventList(object sender, EventArgs args)
{
Navigation.PushModalAsync(new NavigationPage(new IssuesPage(-1)));
}
現在,您將在堆棧中推送一個新的導航頁面,其中包含新的IssuesPage
,並且導航頁面將提供工具欄。 或者,您可以僅使用PushAsync
進行分層導航:
void OnGoToEventList(object sender, EventArgs args)
{
Navigation.PushAsync(new IssuesPage(-1));
}
您應該使用哪一個取決於您的特定用例。 在此博客文章中 ,兩種導航形式都有很好的比較。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.