How to prevent a popover from dismissing when clicking outside in Xamarin with C#?

StackOverflow https://stackoverflow.com/questions/21436249

  •  04-10-2022
  •  | 
  •  

Вопрос

Hello i need to prevent my popover from dismissing when clicking outside the box.

I found some answers but all in objective C and i cant understand it very well.

Stop UIPopover from dismissing automatically

Anyone knows how to do that in xamarin?

Это было полезно?

Решение

UIKit's [UIPopoverControllerDelegate popoverControllerShouldDismissPopover:] translates to UIPopoverControllerDelegate.ShouldDismiss in MonoTouch.

popover.Delegate = new MyPopoverDelegate();

...

class MyPopoverDelegate : UIPopoverControllerDelegate
{
    public override bool ShouldDismiss (UIPopoverController popoverController)
    {
        return false;
    }
}

I'm not completely positive, but I believe you can also just have your main class implement the IUIPopoverControllerDelegate interface and add ShouldDismiss directly to it:

popover.Delegate = this;

...

public override bool ShouldDismiss (UIPopoverController popoverController)
{
    return false;
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top