void OnClick() { Picker model = Element; var picker = new NumberPicker(Context); if (model.Items != null && model.Items.Any()) { picker.MaxValue = model.Items.Count - 1; picker.MinValue = 0; picker.SetDisplayedValues(model.Items.ToArray()); picker.WrapSelectorWheel = false; picker.DescendantFocusability = DescendantFocusability.BlockDescendants; picker.Value = model.SelectedIndex; } var layout = new LinearLayout(Context) { Orientation = Orientation.Vertical }; layout.AddView(picker); ElementController.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, true); var builder = new AlertDialog.Builder(Context); builder.SetView(layout); builder.SetTitle(model.Title ?? ""); builder.SetNegativeButton(Platform.Resource_String_Cancel(), (s, a) => { ElementController.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false); // It is possible for the Content of the Page to be changed when Focus is changed. // In this case, we'll lose our Control. Control?.ClearFocus(); _dialog = null; }); builder.SetPositiveButton(Platform.Resource_String_OK(), (s, a) => { ElementController.SetValueFromRenderer(Picker.SelectedIndexProperty, picker.Value); // It is possible for the Content of the Page to be changed on SelectedIndexChanged. // In this case, the Element & Control will no longer exist. if (Element != null) { if (model.Items.Count > 0 && Element.SelectedIndex >= 0) { Control.Text = model.Items[Element.SelectedIndex]; } ElementController.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false); // It is also possible for the Content of the Page to be changed when Focus is changed. // In this case, we'll lose our Control. Control?.ClearFocus(); } _dialog = null; }); _dialog = builder.Create(); _dialog.DismissEvent += (sender, args) => { ElementController.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false); }; _dialog.Show(); }