gpt4 book ai didi

xaml - Xamarin Forms - 在工具栏项目中显示取消按钮而不是返回 (iOS)

转载 作者:行者123 更新时间:2023-12-04 23:44:55 25 4
gpt4 key购买 nike

我要更改标准Back NavigationBar 中的按钮在 iOS 上发送到 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);
}

最佳答案

完成您的请求的标准约定是 push a Modal并使用 ToolBarItems .您可以在 Xamarin Forums 上找到将 ToolBarItem 应用到您的页面的示例。 .

如果您需要更具体的示例,请告诉我。

更新示例

这两个 ToolbarItems 会像这样:

var cancelItem = new ToolbarItem
{
Text = "Cancel"
};

var doneItem = new ToolbarItem
{
Text = "Done"
};

现在您可以将这些添加到您的 View 中:
this.ToolbarItems.Add(cancelItem);
this.ToolbarItems.Add(doneItem);

您甚至可以绑定(bind) CommandProperty:
doneItem.SetBinding(MenuItem.CommandProperty, "DoneClicked");

或者只是在用户点击项目时处理事件:
doneItem.Clicked += (object sender, System.EventArgs e) => 
{
// Perform action
};

记得到 wrap your Modal in a NavigationPage , 因为 ToolbarItems 否则不会出现。

希望这可以帮助。

关于xaml - Xamarin Forms - 在工具栏项目中显示取消按钮而不是返回 (iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30733917/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com