Android 无法将工具栏项添加到ContentPage
我宣布我的主页:Android 无法将工具栏项添加到ContentPage,android,xamarin,xamarin.android,xamarin.forms,Android,Xamarin,Xamarin.android,Xamarin.forms,我宣布我的主页: public App () { MainPage = new NavigationPage(new MainPage()); } 然后在主页面上点击按钮打开ContantPage: class MainPage : ContentPage { public MainPage() { button.Clicked += to_my_contentpage; //... } private async void t
public App () {
MainPage = new NavigationPage(new MainPage());
}
然后在主页面上点击按钮打开ContantPage:
class MainPage : ContentPage {
public MainPage() {
button.Clicked += to_my_contentpage;
//...
}
private async void to_my_contentpage(object sender, EventArgs e) {
await Navigation.PushModalAsync(new my_contentpage());
//using PushAsync doesn't help
}
}
并尝试将此页面上的按钮显示为工具栏项:
我想根据这个答案做所有事情,但我的工具栏项目不包括在我的页面中:
我做错了什么?PushModalAsync在这种情况下不起作用,因为您需要一个导航栏才能向其中添加工具栏项 由于模式页面没有显式地显示/包含导航栏,因此您不能这样做 解决方案: 创建自定义导航栏并向其中添加所需的任何视图。 不要使用模式页面。 希望这有帮助 添加工具栏项时,需要使用NavigationPage。是否尝试执行等待导航。PushModalAsyncnew NavigationPagenew my_contentpage;?
public class my_contentpage : ContentPage {
public my_contentpage () {
ToolbarItem AddButton = new ToolbarItem("AddButton", "AddIcon.png", () => {
Console.WriteLine("Clicked");
});
this.ToolbarItems.Add(new ToolbarItem());
//...
this.Content = new StackLayout { Children = { header, listView } };
}
}