protected override void OnElementChanged(ElementChangedEventArgs <Picker> e)
        {
            base.OnElementChanged(e);
            if (e.NewElement != null && Control != null)
            {
                element          = (CorePicker)e.NewElement;
                element.Focused += FocusChangedEvent;
                controlColor     = element.EntryColor.ToCGColor();
                if (element.IsEntryUnderline)
                {
                    Control.BorderStyle = UITextBorderStyle.None;
                }

                UpdatePickerPlaceholder();
                if (element.SelectedIndex <= -1)
                {
                    UpdatePickerPlaceholder();
                }

                pickerView = (UIPickerView)Control.InputView;

                if (!string.IsNullOrEmpty(element.FontFamily))
                {
                    var font = UIFont.FromName(element.FontFamily, (nfloat)element.FontSize);
                    Control.Font = font;
                }
            }
        }
Exemple #2
0
        protected override void OnElementChanged(ElementChangedEventArgs <Picker> e)
        {
            if (e.OldElement != null)
            {
                ((INotifyCollectionChanged)e.OldElement.Items).CollectionChanged -= RowsCollectionChanged;
            }

            if (e.NewElement != null)
            {
                element = (CorePicker)e.NewElement;

                if (Control == null)
                {
                    var entry = new NoCaretField {
                        BorderStyle = UITextBorderStyle.RoundedRect
                    };

                    entry.EditingDidBegin += OnStarted;
                    entry.EditingDidEnd   += OnEnded;
                    entry.EditingChanged  += OnEditing;

                    _picker = new UIPickerView();

                    var width   = UIScreen.MainScreen.Bounds.Width;
                    var toolbar = new UIToolbar(new CGRect(0, 0, width, 44))
                    {
                        BarStyle = UIBarStyle.Default, Translucent = true
                    };
                    var spacer     = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace);
                    var doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, (o, a) =>
                    {
                        var s = (PickerSource1)_picker.Model;
                        if (s.SelectedIndex == -1 && Element.Items != null && Element.Items.Count > 0)
                        {
                            UpdatePickerSelectedIndex(0);
                        }
                        UpdatePickerFromModel(s);
                        entry.ResignFirstResponder();
                    });

                    toolbar.SetItems(new[] { spacer, doneButton }, false);

                    entry.InputView          = _picker;
                    entry.InputAccessoryView = toolbar;

                    _defaultTextColor = entry.TextColor;

                    SetNativeControl(entry);
                }

                _picker.Model = new PickerSource1(this);

                UpdatePicker();
                UpdateTextColor();

                ((INotifyCollectionChanged)e.NewElement.Items).CollectionChanged += RowsCollectionChanged;
            }

            base.OnElementChanged(e);
        }
 private void UpdatePickerPlaceholder()
 {
     if (element == null)
     {
         element = Element as CorePicker;
     }
     if (element.Placeholder != null)
     {
         Control.Placeholder = element.Placeholder;
     }
 }