Add a Nav Bar Right Button

PDF for offline use
Related SDKs:

Let us know how you feel about this


0/250

This recipe shows how to add a right button to a navigation bar.

Recipe

To add a button to the UINavigationBar using a built-in icon from the UIBarButtonSystemItem enumeration:

this.NavigationItem.SetRightBarButtonItem(
    new UIBarButtonItem(UIBarButtonSystemItem.Action, (sender,args) => {
       // button was clicked
})
, true);

To add a button to the UINavigationBar using a custom image:

this.NavigationItem.SetRightBarButtonItem(
    new UIBarButtonItem(UIImage.FromFile("some_image.png")
    , UIBarButtonItemStyle.Plain
    , (sender,args) => {
       // button was clicked
    })
, true);

Additional Information

To remove the button:

this.NavigationItem.SetRightBarButtonItem(null, true);

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.