Exemplo n.º 1
0
        protected override void OnElementChanged(ElementChangedEventArgs <Picker> e)
        {
            if (e.OldElement != null)
            {
                ((INotifyCollectionChanged)e.OldElement.Items).CollectionChanged -= RowsCollectionChanged;
            }

            if (e.NewElement != null)
            {
                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 RectangleF(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 = (PickerSource)_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 PickerSource(this);

                UpdateFont();
                UpdatePicker();
                UpdateTextColor();

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

            base.OnElementChanged(e);
        }
        protected override void OnElementChanged(ElementChangedEventArgs <DatePicker> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement == null)
            {
                return;
            }

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

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

                _picker = new UIDatePicker {
                    Mode = UIDatePickerMode.Date, TimeZone = new NSTimeZone("UTC")
                };

                _picker.ValueChanged += HandleValueChanged;

                var width   = UIScreen.MainScreen.Bounds.Width;
                var toolbar = new UIToolbar(new RectangleF(0, 0, width, 44))
                {
                    BarStyle = UIBarStyle.Default, Translucent = true
                };
                var spacer     = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace);
                var doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, (o, a) => entry.ResignFirstResponder());

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

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

                entry.InputView.AutoresizingMask          = UIViewAutoresizing.FlexibleHeight;
                entry.InputAccessoryView.AutoresizingMask = UIViewAutoresizing.FlexibleHeight;

                entry.InputAssistantItem.LeadingBarButtonGroups  = null;
                entry.InputAssistantItem.TrailingBarButtonGroups = null;

                _defaultTextColor = entry.TextColor;

                _useLegacyColorManagement = e.NewElement.UseLegacyColorManagement();

                SetNativeControl(entry);
            }

            UpdateDateFromModel(false);
            UpdateFont();
            UpdateMaximumDate();
            UpdateMinimumDate();
            UpdateTextColor();
            UpdateFlowDirection();
        }
Exemplo n.º 3
0
        protected override void OnElementChanged(ElementChangedEventArgs <DatePicker> e)
        {
            base.OnElementChanged(e);

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

                entry.Started += OnStarted;
                entry.Ended   += OnEnded;

                _picker = new UIDatePicker {
                    Mode = UIDatePickerMode.Date, TimeZone = new NSTimeZone("UTC")
                };

                _picker.ValueChanged += HandleValueChanged;

                var width   = UIScreen.MainScreen.Bounds.Width;
                var toolbar = new UIToolbar(new RectangleF(0, 0, width, 44))
                {
                    BarStyle = UIBarStyle.Default, Translucent = true
                };
                var spacer     = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace);
                var doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, (o, a) => entry.ResignFirstResponder());

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

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

                _defaultTextColor = entry.TextColor;

                SetNativeControl(entry);
            }

            if (e.NewElement != null)
            {
                UpdateDateFromModel(false);
                UpdateMaximumDate();
                UpdateMinimumDate();
                UpdateTextColor();
            }
        }