问题描述
我想将 iOS 上 NavigationBar
中的标准 Back
按钮更改为 Cancel
按钮,例如 iOS 中的新联系人"屏幕.
我正在使用 Xamarin 表单
.
I want to change the standard Back
button in the NavigationBar
on iOS to a Cancel
button like the "New contact" screen in iOS.
I am using 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>
在前一个屏幕中隐藏代码以打开模态
Code-behind in the prior screen to open modal
async Task OpenModal()
{
var page = new NavigationPage(new MyModalView ());
await App.Current.Navigation.PushModalAsync (page);
}
推荐答案
完成您的请求的标准约定是 推送一个 Modal 并使用 ToolBarItems.您可以在 Xamarin 论坛 上找到将 ToolBarItem 应用到您的页面的示例一>.
The standard convention of accomplishing your request is to push a Modal and use ToolBarItems. You can find an example of applying a ToolBarItem to your page on the Xamarin Forums.
如果您需要更具体的示例,请告诉我.
Let me know if you need a more concrete example.
更新示例
两个 ToolbarItems 是这样的:
The two ToolbarItems would like like so:
var cancelItem = new ToolbarItem
{
Text = "Cancel"
};
var doneItem = new ToolbarItem
{
Text = "Done"
};
现在您可以将这些添加到您的视图中:
Now you can add these to your view:
this.ToolbarItems.Add(cancelItem);
this.ToolbarItems.Add(doneItem);
你甚至可以绑定CommandProperty:
You can even bind the CommandProperty:
doneItem.SetBinding(MenuItem.CommandProperty, "DoneClicked");
或者只是在用户点击项目时处理事件:
Or simply handle the event when the user taps the item:
doneItem.Clicked += (object sender, System.EventArgs e) =>
{
// Perform action
};
请记住将您的 Modal 包装在 NavigationPage 中,否则 ToolbarItems 将不会出现.
Remember to wrap your Modal in a NavigationPage, as the ToolbarItems otherwise will not appear.
希望这会有所帮助.
这篇关于Xamarin Forms - 在工具栏项目中显示取消按钮而不是返回 (iOS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!