Xamarin Forms - Show the Cancel button in toolbar items instead of Back (iOS)

I want to change the standard button Backin NavigationBaron iOS to a button Cancelsuch as the New Contact screen in iOS.
I use Xamarin Forms.

EDIT:

Xaml modal

<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 on previous screen to open modal

async Task OpenModal()
{
    var page = new NavigationPage(new MyModalView ());
    await App.Current.Navigation.PushModalAsync (page);
}
+4
source share
2 answers

The standard agreement to fulfill your request is to click Modal and use ToolBarItems . You can find an example of applying ToolBarItem to your page on the Xamarin Forums .

Let me know if you need a more specific example.


UPDATED EXAMPLE

ToolbarItems :

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
};

NavigationPage, ToolbarItems .

, .

+6

, . , .

NavigationPage.SetBackButtonTitle(this, "Cancel");

ContentPage ( ),

+1

All Articles