Using Xamarin Forms, how can the default picker view be changed to show in a PopoverController? The code below throws "Popovers cannot be presented from a view which does not have a window." on iOS.
public class BindablePickerRenderer : PickerRenderer {
private UIPickerView picker;
protected override void OnElementChanged(ElementChangedEventArgs<Picker> e) {
base.OnElementChanged(e);
this.picker = new UIPickerView() {
Source = (UIPickerViewModel) new PickerSource(e.NewElement)
};
var popoverContent = new UIViewController();
popoverContent.View = picker;
var popoverController = new UIPopoverController(popoverContent);
popoverController.PopoverContentSize = new SizeF(320, 180);
popoverController.PresentFromRect(picker.Frame, this.Control.InputView, UIPopoverArrowDirection.Up, true);
}
}
Is this.Control.InputView
the view from which you are presenting the popOverController
? If so, it seems that at the time of OnElementChanged()
execution, your this.Control.InputView
is not a member of the window hierarchy, for whatever reason.
You may want to instead put your popOver-presenting action in an overridden MovedToWindow()
or ViewDidAppear()
. I don't know what type your this.Control.InputView
is, but you'll need to override one of those methods in that type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With