Hello,
You can add a close button on the toolBar, and it can close the picker without selecting anything, please refer to the following code:
public class CustomPickerRenderer:PickerRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
{
base.OnElementChanged(e);
if (Control != null)
{
UIToolbar toolbar = (UIToolbar)Control.InputAccessoryView;
var closeButton = new UIBarButtonItem(UIBarButtonSystemItem.Close, (s, a) =>
{
Control.ResignFirstResponder();
UpdateCharacterSpacing();
});
List<UIBarButtonItem> oldItems = toolbar.Items.ToList();
// oldItems.Add(closeButton);
oldItems.Insert(0, closeButton);//the new button will be positioned on the left side of the toolbar
UIBarButtonItem[] newItems = oldItems.ToArray();
toolbar.SetItems(newItems, false);
}
}
}
Best Regards,
Wenyan Zhang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.