我想将iOS上Back
的标准NavigationBar
按钮更改为Cancel
按钮,例如iOS中的“新联系人”屏幕。
我正在使用Xamarin Forms
。
修改
模态的XAML
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Xrm.Mca.Views.MyModalView">
<ContentPage.ToolbarItems>
<ToolbarItem x:Name="Cancel" Text="Cancel" ></ToolbarItem>
<ToolbarItem x:Name="Save" Text="Save" ></ToolbarItem>
</ContentPage.ToolbarItems>
<ContentPage.Content>
<TableView Intent="Form">
<TableRoot>
<TableSection Title="Details">
<EntryCell Label="Name" Placeholder="Entry your name" />
<EntryCell Label="Age" Placeholder="Entry your age" />
</TableSection>
</TableRoot>
</TableView>
</ContentPage.Content>
</ContentPage>
在前一个屏幕中打开模式的代码隐藏
async Task OpenModal()
{
var page = new NavigationPage(new MyModalView ());
await App.Current.Navigation.PushModalAsync (page);
}
答案 0 :(得分:6)
完成请求的标准惯例是push a Modal并使用ToolBarItems。您可以在Xamarin Forums上找到将ToolBarItem应用于页面的示例。
如果您需要更具体的例子,请告诉我。
更新示例
两个ToolbarItem就像这样:
var cancelItem = new ToolbarItem
{
Text = "Cancel"
};
var doneItem = new ToolbarItem
{
Text = "Done"
};
现在您可以将这些添加到您的视图中:
this.ToolbarItems.Add(cancelItem);
this.ToolbarItems.Add(doneItem);
您甚至可以绑定CommandProperty:
doneItem.SetBinding(MenuItem.CommandProperty, "DoneClicked");
或者只需在用户点按项目时处理该事件:
doneItem.Clicked += (object sender, System.EventArgs e) =>
{
// Perform action
};
请记住wrap your Modal in a NavigationPage,因为否则不会出现ToolbarItem。
希望这有帮助。
答案 1 :(得分:1)
在推送页面的构造函数中执行以下操作
NavigationPage.SetBackButtonTitle(this, "Cancel");
这当然是ContentPage(或任何类型的页面)